正在使用 UISearchController IOS 8,使用 ResultUpDating Delegate
代码如下
- (void)viewDidLoad {
[super viewDidLoad];
self.products = [Product allProducts];
// Create a mutable array to contain products for the search results table.
self.searchResults = [NSMutableArray arrayWithCapacity:[self.products count]];
// The table view controller is in a nav controller, and so the containing nav controller is the 'search results controller'
UINavigationController *searchResultsController = [[self storyboard] instantiateViewControllerWithIdentifier:@"TableSearchResultsNavController"];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.tableView.tableHeaderView = self.searchController.searchBar;
#if ENABLE_SCOPE_BUTTONS
NSMutableArray *scopeButtonTitles = [[NSMutableArray alloc] init];
[scopeButtonTitles addObject:NSLocalizedString(@"All", @"Search display controller All button.")];
for (NSString *deviceType in [Product deviceTypeNames]) {
NSString *displayName = [Product displayNameForType:deviceType];
[scopeButtonTitles addObject:displayName];
}
self.searchController.searchBar.scopeButtonTitles = scopeButtonTitles;
self.searchController.searchBar.delegate = self;
#endif
self.definesPresentationContext = YES;
}
委托(delegate)方法是
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
// Set searchString equal to what's typed into the searchbar
NSString *searchString = self.searchController.searchBar.text;
//NSLog(@"o");
[self fetchByPatientName:searchString];
}
- (void)fetchByPatientName:(NSString *)patientName
{
//Code TO Fetch
// Code To Update Table
}
我的 Storyboard [ ][1
运行后我得到两个搜索栏,我正在寻找如何解决它
非常感谢您的帮助。
最佳答案
删除以下内容应该可以解决问题
self.tableView.tableHeaderView = self.searchController.searchBar
关于ios - 搜索栏 IOS 8 - 显示两个搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34586910/