Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fdc9812

Browse files
注册 - 支持全球验证码
1 parent 7d77dc0 commit fdc9812

File tree

11 files changed

+2389
-27
lines changed

11 files changed

+2389
-27
lines changed

‎Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@
561561
4EBB624C1A6F526C0045DAEF /* NJKWebViewProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EBB62491A6F526C0045DAEF /* NJKWebViewProgress.m */; };
562562
4EBB624D1A6F526C0045DAEF /* NJKWebViewProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EBB624B1A6F526C0045DAEF /* NJKWebViewProgressView.m */; };
563563
4EBD0C661A1F2011004B4284 /* nav_project_file@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EBD0C651A1F2011004B4284 /* nav_project_file@2x.png */; };
564+
4EBD7FAF1CE4827A00B3AF49 /* CountryCodeListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EBD7FAE1CE4827A00B3AF49 /* CountryCodeListViewController.m */; };
565+
4EBD7FB11CE482A400B3AF49 /* country_code.plist in Resources */ = {isa = PBXBuildFile; fileRef = 4EBD7FB01CE482A400B3AF49 /* country_code.plist */; };
566+
4EBD7FB41CE4833D00B3AF49 /* CountryCodeCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EBD7FB31CE4833D00B3AF49 /* CountryCodeCell.m */; };
564567
4EBDA87C1A6640340035ED96 /* UIActionSheet+Common.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EBDA87B1A6640340035ED96 /* UIActionSheet+Common.m */; };
565568
4EBDC27B1BC501C00037EB66 /* tipIcon_ProjectPayment@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EBDC27A1BC501C00037EB66 /* tipIcon_ProjectPayment@2x.png */; };
566569
4EBFBD181AA85B8500E4B10E /* add_user_icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EBFBD171AA85B8500E4B10E /* add_user_icon@2x.png */; };
@@ -1959,6 +1962,11 @@
19591962
4EBB624A1A6F526C0045DAEF /* NJKWebViewProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJKWebViewProgressView.h; sourceTree = "<group>"; };
19601963
4EBB624B1A6F526C0045DAEF /* NJKWebViewProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJKWebViewProgressView.m; sourceTree = "<group>"; };
19611964
4EBD0C651A1F2011004B4284 /* nav_project_file@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "nav_project_file@2x.png"; sourceTree = "<group>"; };
1965+
4EBD7FAD1CE4827A00B3AF49 /* CountryCodeListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CountryCodeListViewController.h; sourceTree = "<group>"; };
1966+
4EBD7FAE1CE4827A00B3AF49 /* CountryCodeListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CountryCodeListViewController.m; sourceTree = "<group>"; };
1967+
4EBD7FB01CE482A400B3AF49 /* country_code.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = country_code.plist; sourceTree = "<group>"; };
1968+
4EBD7FB21CE4833D00B3AF49 /* CountryCodeCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CountryCodeCell.h; sourceTree = "<group>"; };
1969+
4EBD7FB31CE4833D00B3AF49 /* CountryCodeCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CountryCodeCell.m; sourceTree = "<group>"; };
19621970
4EBDA87A1A6640340035ED96 /* UIActionSheet+Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIActionSheet+Common.h"; sourceTree = "<group>"; };
19631971
4EBDA87B1A6640340035ED96 /* UIActionSheet+Common.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIActionSheet+Common.m"; sourceTree = "<group>"; };
19641972
4EBDC27A1BC501C00037EB66 /* tipIcon_ProjectPayment@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tipIcon_ProjectPayment@2x.png"; sourceTree = "<group>"; };
@@ -4651,6 +4659,8 @@
46514659
D09E6AD01BF9D999009D37F8 /* SearchViewController.m */,
46524660
D09AA5B51BFDA38D008CA9EB /* AllSearchDisplayVC.h */,
46534661
D09AA5B61BFDA38D008CA9EB /* AllSearchDisplayVC.m */,
4662+
4EBD7FAD1CE4827A00B3AF49 /* CountryCodeListViewController.h */,
4663+
4EBD7FAE1CE4827A00B3AF49 /* CountryCodeListViewController.m */,
46544664
);
46554665
path = Controllers;
46564666
sourceTree = "<group>";
@@ -5083,6 +5093,7 @@
50835093
4EE083DD1ADB739300CA342E /* modules */,
50845094
4EE083DB1ADB736800CA342E /* service_terms.html */,
50855095
4E753D471B8DA099003A00B9 /* diff-ios.html */,
5096+
4EBD7FB01CE482A400B3AF49 /* country_code.plist */,
50865097
8E1C3DF519E7F4CA00EF3032 /* address.json */,
50875098
4E1209FB1C8814A20087BDB3 /* GoogleService-Info.plist */,
50885099
);
@@ -5524,6 +5535,8 @@
55245535
4EB52F271C76ED4A00B5EBEA /* TagColorEditCell.m */,
55255536
4EB52F291C76ED7000B5EBEA /* TagColorDisplayCell.h */,
55265537
4EB52F2A1C76ED7000B5EBEA /* TagColorDisplayCell.m */,
5538+
4EBD7FB21CE4833D00B3AF49 /* CountryCodeCell.h */,
5539+
4EBD7FB31CE4833D00B3AF49 /* CountryCodeCell.m */,
55275540
);
55285541
path = Cell;
55295542
sourceTree = "<group>";
@@ -5964,6 +5977,7 @@
59645977
4EBD0C661A1F2011004B4284 /* nav_project_file@2x.png in Resources */,
59655978
D0C447C31C02DB5400DC1C4B /* pop_Task@2x.png in Resources */,
59665979
8EA6D17E19E240C40076D59C /* section_btn_close@2x.png in Resources */,
5980+
4EBD7FB11CE482A400B3AF49 /* country_code.plist in Resources */,
59675981
4E93F23C1B84356500017916 /* file_menu_icon_info@2x.png in Resources */,
59685982
8E97CE9E1A0C7E26006F9AD7 /* coding_emoji_07@2x.png in Resources */,
59695983
13FB5D461CA17A6400EE127C /* merge-request coding@3x.png in Resources */,
@@ -6481,6 +6495,7 @@
64816495
136A6DBC1CAF52F2004AA983 /* MRPRPreInfo.m in Sources */,
64826496
4E72F82D1B144778001B6CE6 /* NSMutableString+Common.m in Sources */,
64836497
4E25271A1C327FAE0032A7F4 /* UIViewController+BackButtonHandler.m in Sources */,
6498+
4EBD7FB41CE4833D00B3AF49 /* CountryCodeCell.m in Sources */,
64846499
13C8FE7F1CA79B90001E30FA /* DynamicActivityCell.m in Sources */,
64856500
4E4D6A791B1C6C7800FD2E49 /* MRPRDetailCell.m in Sources */,
64866501
8EF643CA19FF7E2900F7EEB0 /* TopicContentCell.m in Sources */,
@@ -6522,6 +6537,7 @@
65226537
8EF643D119FF7E2900F7EEB0 /* TweetSendTextCell.m in Sources */,
65236538
8EA6D22319E240C40076D59C /* XTSegmentControl.m in Sources */,
65246539
4E6D71891A75F00E005AD988 /* YLGIFImage.m in Sources */,
6540+
4EBD7FAF1CE4827A00B3AF49 /* CountryCodeListViewController.m in Sources */,
65256541
D09AA5B71BFDA38D008CA9EB /* AllSearchDisplayVC.m in Sources */,
65266542
0A27A05D1AB5A13B00067833 /* TweetSendLocationDetailViewController.m in Sources */,
65276543
0AB591B01AB6D6BE0076C454 /* TweetSendMapAnnotation.m in Sources */,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// CountryCodeListViewController.h
3+
// CodingMart
4+
//
5+
// Created by Ease on 16/5/11.
6+
// Copyright © 2016年 net.coding. All rights reserved.
7+
//
8+
9+
#import "BaseViewController.h"
10+
11+
@interface CountryCodeListViewController : BaseViewController
12+
@property (copy, nonatomic) void(^selectedBlock)(NSDictionary *countryCodeDict);//country, country_code, iso_code
13+
14+
@end
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
//
2+
// CountryCodeListViewController.m
3+
// CodingMart
4+
//
5+
// Created by Ease on 16/5/11.
6+
// Copyright © 2016年 net.coding. All rights reserved.
7+
//
8+
9+
#import "CountryCodeListViewController.h"
10+
#import "CountryCodeCell.h"
11+
12+
@interface CountryCodeListViewController ()<UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
13+
@property (strong, nonatomic) UISearchBar *mySearchBar;
14+
@property (strong, nonatomic) UITableView *myTableView;
15+
@property (strong, nonatomic) NSDictionary *countryCodeListDict, *searchResults;
16+
@property (strong, nonatomic) NSMutableArray *keyList;
17+
18+
@end
19+
20+
@implementation CountryCodeListViewController
21+
- (void)viewDidLoad{
22+
[super viewDidLoad];
23+
self.title = @"选择国家或地区";
24+
_myTableView = ({
25+
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
26+
tableView.backgroundColor = kColorTableSectionBg;
27+
tableView.delegate = self;
28+
tableView.dataSource = self;
29+
[tableView registerClass:[CountryCodeCell class] forCellReuseIdentifier:kCellIdentifier_CountryCodeCell];
30+
tableView.sectionIndexBackgroundColor = [UIColor clearColor];
31+
tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
32+
tableView.sectionIndexColor = [UIColor colorWithHexString:@"0x666666"];
33+
[self.view addSubview:tableView];
34+
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
35+
make.edges.equalTo(self.view);
36+
}];
37+
tableView;
38+
});
39+
_mySearchBar = ({
40+
UISearchBar *searchBar = [UISearchBar new];
41+
searchBar.delegate = self;
42+
[searchBar sizeToFit];
43+
[searchBar setPlaceholder:@"国家/地区名称"];
44+
searchBar;
45+
});
46+
[self setupData];
47+
48+
_myTableView.tableHeaderView = _mySearchBar;
49+
_myTableView.tableFooterView = [UIView new];
50+
}
51+
52+
#pragma mark Data
53+
- (void)setupData{
54+
NSString *path = [[NSBundle mainBundle] pathForResource:@"country_code" ofType:@"plist"];
55+
_searchResults = _countryCodeListDict = [NSDictionary dictionaryWithContentsOfFile:path];
56+
[self p_updateKeyList];
57+
}
58+
59+
- (void)p_updateKeyList{
60+
_keyList = [_searchResults allKeys].mutableCopy;
61+
[_keyList sortUsingComparator:^NSComparisonResult(NSString * _Nonnull obj1, NSString * _Nonnull obj2) {
62+
if ([obj1 isEqualToString:@"#"]) {
63+
return NSOrderedAscending;
64+
}else if ([obj2 isEqualToString:@"#"]){
65+
return NSOrderedDescending;
66+
}else{
67+
return [obj1 compare:obj2];
68+
}
69+
}];
70+
[_keyList insertObject:UITableViewIndexSearch atIndex:0];
71+
}
72+
73+
#pragma mark Table M
74+
75+
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
76+
if (scrollView == self.myTableView) {
77+
[_mySearchBar resignFirstResponder];
78+
}
79+
}
80+
81+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
82+
return _keyList.count - 1;
83+
}
84+
85+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
86+
return [_searchResults[_keyList[section+ 1]] count];
87+
}
88+
89+
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
90+
return index > 0? index - 1: index;
91+
}
92+
93+
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
94+
return _keyList;
95+
}
96+
97+
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
98+
return 20;
99+
}
100+
101+
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
102+
UIView *headerV = [UIView new];
103+
headerV.backgroundColor = self.myTableView.backgroundColor;
104+
UILabel *titleL = [UILabel new];
105+
titleL.font = [UIFont systemFontOfSize:12];
106+
titleL.textColor = [UIColor colorWithHexString:@"0x999999"];
107+
titleL.text = [_keyList[section+ 1] isEqualToString:@"#"]? @"常用地区": _keyList[section+ 1];
108+
[headerV addSubview:titleL];
109+
[titleL mas_makeConstraints:^(MASConstraintMaker *make) {
110+
make.edges.equalTo(headerV).insets(UIEdgeInsetsMake(4, 15, 4, 15));
111+
}];
112+
return headerV;
113+
}
114+
115+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
116+
CountryCodeCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_CountryCodeCell forIndexPath:indexPath];
117+
cell.countryCodeDict = _searchResults[_keyList[indexPath.section+ 1]][indexPath.row];
118+
return cell;
119+
}
120+
121+
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
122+
cell.separatorInset = UIEdgeInsetsMake(0, 15, 0, (kScreen_Width - cell.contentView.width) + 15);
123+
}
124+
125+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
126+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
127+
if (_selectedBlock) {
128+
_selectedBlock(_searchResults[_keyList[indexPath.section+ 1]][indexPath.row]);
129+
}
130+
[self.navigationController popViewControllerAnimated:YES];
131+
}
132+
133+
#pragma mark UISearchBarDelegate
134+
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
135+
NSMutableDictionary *searchResults = @{}.mutableCopy;
136+
NSString *strippedStr = [searchText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
137+
NSArray *searchItems = [strippedStr componentsSeparatedByString:@" "];
138+
if (strippedStr.length == 0) {
139+
searchResults = _countryCodeListDict.mutableCopy;
140+
}else{
141+
NSMutableArray *andMatchPredicates = [NSMutableArray array];
142+
for (NSString *searchString in searchItems){
143+
NSMutableArray *searchItemsPredicate = [NSMutableArray new];
144+
145+
NSExpression *lhs = [NSExpression expressionForKeyPath:@"country"];
146+
NSExpression *rhs = [NSExpression expressionForConstantValue:searchString];
147+
NSPredicate *finalPredicate = [NSComparisonPredicate
148+
predicateWithLeftExpression:lhs
149+
rightExpression:rhs
150+
modifier:NSDirectPredicateModifier
151+
type:NSContainsPredicateOperatorType
152+
options:NSCaseInsensitivePredicateOption];
153+
[searchItemsPredicate addObject:finalPredicate];
154+
155+
lhs = [NSExpression expressionForKeyPath:@"country_code"];
156+
rhs = [NSExpression expressionForConstantValue:searchString];
157+
finalPredicate = [NSComparisonPredicate
158+
predicateWithLeftExpression:lhs
159+
rightExpression:rhs
160+
modifier:NSDirectPredicateModifier
161+
type:NSContainsPredicateOperatorType
162+
options:NSCaseInsensitivePredicateOption];
163+
[searchItemsPredicate addObject:finalPredicate];
164+
165+
lhs = [NSExpression expressionForKeyPath:@"iso_code"];
166+
rhs = [NSExpression expressionForConstantValue:searchString];
167+
finalPredicate = [NSComparisonPredicate
168+
predicateWithLeftExpression:lhs
169+
rightExpression:rhs
170+
modifier:NSDirectPredicateModifier
171+
type:NSContainsPredicateOperatorType
172+
options:NSCaseInsensitivePredicateOption];
173+
[searchItemsPredicate addObject:finalPredicate];
174+
175+
NSCompoundPredicate *orMatchPredicates = (NSCompoundPredicate *)[NSCompoundPredicate orPredicateWithSubpredicates:searchItemsPredicate];
176+
[andMatchPredicates addObject:orMatchPredicates];
177+
}
178+
NSCompoundPredicate *finalCompoundPredicate = (NSCompoundPredicate *)[NSCompoundPredicate andPredicateWithSubpredicates:andMatchPredicates];
179+
for (NSString *key in [_countryCodeListDict allKeys]) {
180+
NSArray *finalList = [_countryCodeListDict[key] filteredArrayUsingPredicate:finalCompoundPredicate];
181+
if (finalList.count > 0) {
182+
[searchResults setValue:finalList forKey:key];
183+
}else{
184+
[searchResults removeObjectForKey:key];
185+
}
186+
}
187+
}
188+
_searchResults = searchResults;
189+
[self p_updateKeyList];
190+
[self.myTableView reloadData];
191+
}
192+
193+
194+
@end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /