IOS searchBar和searchDisplayController 使用

一、加的是searchDisplayController 能够在storyboard中看到 seachDisplayhtml

二、两个代理  UISearchBarDelegate,UISearchDisplayDelegate 并设置spa

三、连线 searchDisplay和searchBar代理

四、将 self.tableView.tableHeaderView=self.searchBar 固定住code

五、搜索时调用的方法orm

#pragma mark 搜索方法htm

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{blog


    NSPredicate * query=[NSPredicate predicateWithFormat:@"SELF.name contains[c]%@",searchString];it

    

    self.searchResult=[self.contacts filteredArrayUsingPredicate:query];table

    

    return YES;class

}




六、搜索的时候会显示本身的tableView  肯定是否是searchDisplay.searchResultsTableView

七、修改tableView  count

八、跳转判断 查看联系人 

#prama mark 点击搜索后搜索
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    NSString * searchString=self.searchBar.text;
    
    NSPredicate * query=[NSPredicate predicateWithFormat:@"SELF.title contains[c]%@",searchString];
    
    self.searchResult=[self.searchData filteredArrayUsingPredicate:query];
    NSLog(@"self.searchResult%@",self.searchResult);
    [self.searchDisplay.searchResultsTableView reloadData];
}

/*

#pragma mark 实时搜索
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
    
    
    NSPredicate * query=[NSPredicate predicateWithFormat:@"SELF.title contains[c]%@",searchString];
    
    self.searchResult=[self.searchData filteredArrayUsingPredicate:query];
    return YES;
}
*/


参考资料

http://www.cnblogs.com/lesliefang/p/3929677.html

相关文章
相关标签/搜索