UITableView 如何实现搜索框功能
1。定义如下两个变量,并且声明为属性。
UISearchBar * searchBar;
UISearchDisplayController * searchDc;
2。在loadView中,初始化 这两个控件
3。在 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
函数中,对搜索控制器做特殊化处理。
4。在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中,根据 是否是搜索控制器,返回不同的cell 数据。
5。在 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
等等需要特殊处理的函数中,都加上对搜索控制器的 特殊处理。