注册页面国家代码闪退修改
This commit is contained in:
parent
4addf7e817
commit
68d139a184
|
|
@ -12,11 +12,11 @@
|
||||||
#define CURR_LANG ([[NSLocale preferredLanguages] objectAtIndex:0])
|
#define CURR_LANG ([[NSLocale preferredLanguages] objectAtIndex:0])
|
||||||
#define LanguageIsEnglish ([CURR_LANG isEqualToString:@"en-US"] || [CURR_LANG isEqualToString:@"en-CA"] || [CURR_LANG isEqualToString:@"en-GB"] || [CURR_LANG isEqualToString:@"en-CN"] || [CURR_LANG isEqualToString:@"en"])
|
#define LanguageIsEnglish ([CURR_LANG isEqualToString:@"en-US"] || [CURR_LANG isEqualToString:@"en-CA"] || [CURR_LANG isEqualToString:@"en-GB"] || [CURR_LANG isEqualToString:@"en-CN"] || [CURR_LANG isEqualToString:@"en"])
|
||||||
|
|
||||||
@interface XWCountryCodeController()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UISearchDisplayDelegate>{
|
@interface XWCountryCodeController()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UISearchResultsUpdating>{
|
||||||
//国际代码主tableview
|
//国际代码主tableview
|
||||||
UITableView *countryCodeTableView;
|
UITableView *countryCodeTableView;
|
||||||
//搜索
|
//搜索
|
||||||
UISearchDisplayController *searchController;
|
UISearchController *searchController;
|
||||||
// UISearchController *searchController;
|
// UISearchController *searchController;
|
||||||
UISearchBar *searchBar;
|
UISearchBar *searchBar;
|
||||||
//代码字典
|
//代码字典
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
-(void)creatSubviews{
|
-(void)creatSubviews{
|
||||||
searchResultValuesArray = [[NSMutableArray alloc] init];
|
searchResultValuesArray = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
countryCodeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height-20) style:UITableViewStylePlain];
|
countryCodeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height-40) style:UITableViewStylePlain];
|
||||||
[self.view addSubview:countryCodeTableView];
|
[self.view addSubview:countryCodeTableView];
|
||||||
//自动调整自己的宽度,保证与superView左边和右边的距离不变。
|
//自动调整自己的宽度,保证与superView左边和右边的距离不变。
|
||||||
[countryCodeTableView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
|
[countryCodeTableView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
|
||||||
|
|
@ -61,18 +61,15 @@
|
||||||
[countryCodeTableView setDelegate:self];
|
[countryCodeTableView setDelegate:self];
|
||||||
[countryCodeTableView setSectionIndexBackgroundColor:[UIColor clearColor]];
|
[countryCodeTableView setSectionIndexBackgroundColor:[UIColor clearColor]];
|
||||||
|
|
||||||
searchBar = [[UISearchBar alloc] init];
|
|
||||||
[searchBar sizeToFit];
|
|
||||||
[searchBar setDelegate:self];
|
|
||||||
//关闭系统自动联想和首字母大写功能
|
|
||||||
[searchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone];
|
|
||||||
[countryCodeTableView setTableHeaderView:searchBar];
|
|
||||||
|
|
||||||
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
|
|
||||||
[searchController setDelegate:self];
|
|
||||||
searchController.searchResultsDataSource = self;
|
|
||||||
searchController.searchResultsDelegate = self;
|
|
||||||
|
|
||||||
|
searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
|
||||||
|
[searchController setSearchResultsUpdater:self];
|
||||||
|
searchController.dimsBackgroundDuringPresentation=NO;
|
||||||
|
searchController.definesPresentationContext=NO;
|
||||||
|
searchController.searchBar.delegate=self;
|
||||||
|
countryCodeTableView.tableHeaderView=searchController.searchBar;
|
||||||
|
searchBar=searchController.searchBar;
|
||||||
NSString *plistPathCH = [[NSBundle mainBundle] pathForResource:@"sortedChnames" ofType:@"plist"];
|
NSString *plistPathCH = [[NSBundle mainBundle] pathForResource:@"sortedChnames" ofType:@"plist"];
|
||||||
NSString *plistPathEN = [[NSBundle mainBundle] pathForResource:@"sortedEnames" ofType:@"plist"];
|
NSString *plistPathEN = [[NSBundle mainBundle] pathForResource:@"sortedEnames" ofType:@"plist"];
|
||||||
|
|
||||||
|
|
@ -91,25 +88,29 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//搜索
|
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
|
||||||
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
|
{
|
||||||
NSLog(@"%s",__FUNCTION__);
|
NSLog(@"%s",__FUNCTION__);
|
||||||
[searchResultValuesArray removeAllObjects];
|
[searchResultValuesArray removeAllObjects];
|
||||||
|
|
||||||
for (NSArray *array in [sortedNameDict allValues]) {
|
for (NSArray *array in [sortedNameDict allValues]) {
|
||||||
for (NSString *value in array) {
|
for (NSString *value in array) {
|
||||||
if ([value containsString:searchBar.text]) {
|
if ([value containsString:searchController.searchBar.text]) {
|
||||||
[searchResultValuesArray addObject:value];
|
[searchResultValuesArray addObject:value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[searchController.searchResultsTableView reloadData];
|
|
||||||
|
|
||||||
|
[countryCodeTableView reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - UITableView
|
#pragma mark - UITableView
|
||||||
//section
|
//section
|
||||||
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
||||||
if (tableView == countryCodeTableView) {
|
if (!searchController.isActive) {
|
||||||
return [sortedNameDict allKeys].count;
|
return [sortedNameDict allKeys].count;
|
||||||
}else{
|
}else{
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -117,7 +118,7 @@
|
||||||
}
|
}
|
||||||
//row
|
//row
|
||||||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||||||
if (tableView == countryCodeTableView) {
|
if (!searchController.isActive) {
|
||||||
|
|
||||||
NSArray *array = [sortedNameDict objectForKey:[indexArray objectAtIndex:section]];
|
NSArray *array = [sortedNameDict objectForKey:[indexArray objectAtIndex:section]];
|
||||||
return array.count;
|
return array.count;
|
||||||
|
|
@ -134,7 +135,7 @@
|
||||||
|
|
||||||
//初始化cell
|
//初始化cell
|
||||||
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||||
if (tableView == countryCodeTableView) {
|
if (!searchController.isActive) {
|
||||||
static NSString *ID1 = @"cellIdentifier1";
|
static NSString *ID1 = @"cellIdentifier1";
|
||||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID1];
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID1];
|
||||||
if (!cell) {
|
if (!cell) {
|
||||||
|
|
@ -164,7 +165,7 @@
|
||||||
|
|
||||||
//indexTitle
|
//indexTitle
|
||||||
-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{
|
-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{
|
||||||
if (tableView == countryCodeTableView) {
|
if (!searchController.isActive) {
|
||||||
return indexArray;
|
return indexArray;
|
||||||
}else{
|
}else{
|
||||||
return nil;
|
return nil;
|
||||||
|
|
@ -172,7 +173,7 @@
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
|
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
|
||||||
if (tableView == countryCodeTableView) {
|
if (!searchController.isActive) {
|
||||||
return index;
|
return index;
|
||||||
}else{
|
}else{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -181,7 +182,7 @@
|
||||||
|
|
||||||
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||||
{
|
{
|
||||||
if (tableView == countryCodeTableView) {
|
if (!searchController.isActive) {
|
||||||
if (section == 0) {
|
if (section == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -212,6 +213,9 @@
|
||||||
if (self.returnCountryCodeBlock != nil) {
|
if (self.returnCountryCodeBlock != nil) {
|
||||||
self.returnCountryCodeBlock(cell.textLabel.text);
|
self.returnCountryCodeBlock(cell.textLabel.text);
|
||||||
}
|
}
|
||||||
|
if (searchController.isActive) {
|
||||||
|
[searchController dismissViewControllerAnimated:YES completion:nil];
|
||||||
|
}
|
||||||
[self dismissViewControllerAnimated:YES completion:nil];
|
[self dismissViewControllerAnimated:YES completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue