tableView加searchBar,以搜索通讯录为列
来源:互联网 发布:ubuntu改变文件所有者 编辑:程序博客网 时间:2024/06/05 13:10
使用的是storyBoard
1拖一个UISearchDisplayController到tableView的headerView上,并声明成全局变量
@property (strong,nonatomic) IBOutletUISearchDisplayController *searchDispalyController;
@property (weak, nonatomic) IBOutletUISearchBar *searchBar;
@property (nonatomic,strong) NSArray * resultModelArr;
2实现代理方法
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {
NSPredicate* cate=[NSPredicatepredicateWithFormat:@"(SELF.name contains [c] %@) OR ( SELF.phone contains [c] %@)",
self.searchBar.text,
self.searchBar.text
];
self.resultModelArr=[self.modelArrayfilteredArrayUsingPredicate:cate];
//modelArray 封装的person对象,有name和phone两种属性
}
#pragma mark - UISearchDisplayController delegate methods
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[selffilterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBarscopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
[selffilterContentForSearchText:[self.searchDisplayController.searchBartext] scope:[[self.searchDisplayController.searchBarscopeButtonTitles]objectAtIndex:searchOption]];
return YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == self.searchDispalyController.searchResultsTableView) {
return_resultModelArr.count;
}else{
return _modelArray.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PhoneContactCell *cell = [self.tableViewdequeueReusableCellWithIdentifier:@"PhoneContactCell"forIndexPath:indexPath];//要用self.tableView 否则会崩溃
PhoneContactModel * model;
if (tableView == self.searchDispalyController.searchResultsTableView) {
model=_resultModelArr[indexPath.row];
}else{
model=_modelArray[indexPath.row];
}
[cellsetModel:model];
return cell;
}
- tableView加searchBar,以搜索通讯录为列
- 给TableView增加SearchBar
- IOS开发搜索和排序(好友列表 通讯录的实现 searchbar)
- 在tableview上添加searchbar
- SearchBar、Tableview右边的英文A-Z背景色设置为任意颜色
- 模糊搜索(searchBar)
- 模糊搜索(searchBar)
- qml为TableView动态插入列
- iOS开发 给TableView增加SearchBar
- 【代码笔记】iOS-scrollerView里多个tableView加搜索框
- searchbar自动匹配搜索内容
- 简单的TableView通讯录
- 为GridView 加按钮列之后,(ButtonField)
- SQL_为表和列加注释
- db2数据库 为列加注释
- 为表视图添加searchBar
- 以链表为主体设计的通讯录
- tableView搜索
- springMVC @ResponseBody 返回结果乱码
- Logcat源码分析(一)
- 怎样正确的使用QThread类
- 第十一周---求两个数的最大公约数
- 第11周项目--调用函数之求最大公约数
- tableView加searchBar,以搜索通讯录为列
- kerberos 安装和配置
- 编程:函数版星号图 printchs函数
- 第11周项目一 函数版星号图(2)
- 第十一周 项目2:求最大公约数
- 第十周项目一。2
- photoshop 高手之路
- AssetBundle系列——游戏资源打包(二)
- php加密解密功能类