注册页面国家代码闪退修改
This commit is contained in:
parent
4addf7e817
commit
68d139a184
|
|
@ -12,11 +12,11 @@
|
|||
#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"])
|
||||
|
||||
@interface XWCountryCodeController()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UISearchDisplayDelegate>{
|
||||
@interface XWCountryCodeController()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UISearchResultsUpdating>{
|
||||
//国际代码主tableview
|
||||
UITableView *countryCodeTableView;
|
||||
//搜索
|
||||
UISearchDisplayController *searchController;
|
||||
UISearchController *searchController;
|
||||
// UISearchController *searchController;
|
||||
UISearchBar *searchBar;
|
||||
//代码字典
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
-(void)creatSubviews{
|
||||
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];
|
||||
//自动调整自己的宽度,保证与superView左边和右边的距离不变。
|
||||
[countryCodeTableView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
|
||||
|
|
@ -61,18 +61,15 @@
|
|||
[countryCodeTableView setDelegate:self];
|
||||
[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 *plistPathEN = [[NSBundle mainBundle] pathForResource:@"sortedEnames" ofType:@"plist"];
|
||||
|
||||
|
|
@ -91,25 +88,29 @@
|
|||
|
||||
}
|
||||
|
||||
//搜索
|
||||
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
|
||||
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
|
||||
{
|
||||
NSLog(@"%s",__FUNCTION__);
|
||||
[searchResultValuesArray removeAllObjects];
|
||||
|
||||
for (NSArray *array in [sortedNameDict allValues]) {
|
||||
for (NSString *value in array) {
|
||||
if ([value containsString:searchBar.text]) {
|
||||
if ([value containsString:searchController.searchBar.text]) {
|
||||
[searchResultValuesArray addObject:value];
|
||||
}
|
||||
}
|
||||
}
|
||||
[searchController.searchResultsTableView reloadData];
|
||||
|
||||
|
||||
[countryCodeTableView reloadData];
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma mark - UITableView
|
||||
//section
|
||||
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
||||
if (tableView == countryCodeTableView) {
|
||||
if (!searchController.isActive) {
|
||||
return [sortedNameDict allKeys].count;
|
||||
}else{
|
||||
return 1;
|
||||
|
|
@ -117,7 +118,7 @@
|
|||
}
|
||||
//row
|
||||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||||
if (tableView == countryCodeTableView) {
|
||||
if (!searchController.isActive) {
|
||||
|
||||
NSArray *array = [sortedNameDict objectForKey:[indexArray objectAtIndex:section]];
|
||||
return array.count;
|
||||
|
|
@ -134,7 +135,7 @@
|
|||
|
||||
//初始化cell
|
||||
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
if (tableView == countryCodeTableView) {
|
||||
if (!searchController.isActive) {
|
||||
static NSString *ID1 = @"cellIdentifier1";
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID1];
|
||||
if (!cell) {
|
||||
|
|
@ -164,7 +165,7 @@
|
|||
|
||||
//indexTitle
|
||||
-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{
|
||||
if (tableView == countryCodeTableView) {
|
||||
if (!searchController.isActive) {
|
||||
return indexArray;
|
||||
}else{
|
||||
return nil;
|
||||
|
|
@ -172,7 +173,7 @@
|
|||
}
|
||||
//
|
||||
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
|
||||
if (tableView == countryCodeTableView) {
|
||||
if (!searchController.isActive) {
|
||||
return index;
|
||||
}else{
|
||||
return 0;
|
||||
|
|
@ -181,7 +182,7 @@
|
|||
|
||||
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
if (tableView == countryCodeTableView) {
|
||||
if (!searchController.isActive) {
|
||||
if (section == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -212,6 +213,9 @@
|
|||
if (self.returnCountryCodeBlock != nil) {
|
||||
self.returnCountryCodeBlock(cell.textLabel.text);
|
||||
}
|
||||
if (searchController.isActive) {
|
||||
[searchController dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue