iOS 7 Search Bar - Cancel button doesn't work
我在 iOS 6 应用程序中有一个
我的代码是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { // -- iOS 7 Hack if (!SYSTEM_VERSION_LESS_THAN(@"7.0")) { controller.searchResultsTableView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64); [controller.searchContentsController.view setNeedsLayout]; } [self filterContentForSearchText:searchString scope:nil]; return YES; } - (void) searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { // iOS7 Hack if (!SYSTEM_VERSION_LESS_THAN(@"7.0")) { controller.searchResultsTableView.contentInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, 0.f); } } |
感谢您的提前。
可能重复:UISearchBar 的取消和清除按钮在 iOS 7 中不起作用
编辑:
1 2 3 4 5 6 | - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { self.searchDisplayController.searchBar.hidden = YES; self.tempImageView.hidden = NO; [searchBar resignFirstResponder]; } |
解决方案:
通过这个功能我解决了这个问题:
1 2 3 4 5 6 7 | -(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller { controller.active = YES; [self.view addSubview:controller.searchBar]; [self.view bringSubviewToFront:controller.searchBar]; } |
希望对你有帮助!
通过这个功能我解决了这个问题:
1 2 3 4 5 6 7 | -(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller { controller.active = YES; [self.view addSubview:controller.searchBar]; [self.view bringSubviewToFront:controller.searchBar]; } |
希望对你有帮助!
IOS 7 默认搜索栏将是透明的取消按钮
1 2 3 4 5 6 7 8 9 | - (void)searchBarCancelButtonClicked:(UISearchBar *)aSearchBar { [aSearchBar resignFirstResponder]; isSearching = NO; aSearchBar.text = @""; [diaryTableView reloadData]; } |