使用UISearchController IOS 8,使用ResultUpDating委托
以下代码
- (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;
}
代表方法
-(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
}
My Stroy Board [] [1
Aftr运行我的两个SearchBars,我正在寻求如何解决它
您的帮助,不胜感激。
答案 0 :(得分:0)
删除以下内容应解决它
self.tableView.tableHeaderView = self.searchController.searchBar