ios在UITableViewController里使用UISearchDisplayController报错"[UISearchResultsTableView dequeueReusableCel
来源:互联网 发布:鬼刀精装画册淘宝 编辑:程序博客网 时间:2024/06/07 03:16
我尝试在我的APP里添加一个简单的搜索功能到TableViewController .我按照Ray Wenderlich的教程.我有一个一些数据的tableView,我在storyboard里添加了搜索条+显示控制器,下面就是我的代码:
#pragma mark - Table View
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BreedCell" forIndexPath:indexPath];
//Create PetBreed Object and return corresponding breed from corresponding array
PetBreed *petBreed = nil;
if(tableView == self.searchDisplayController.searchResultsTableView)
petBreed = [_filteredBreedsArray objectAtIndex:indexPath.row];
else
petBreed = [_breedsArray objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = petBreed.name;
return cell;
}
#pragma mark - Search
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[_filteredBreedsArray removeAllObjects];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",searchString];
_filteredBreedsArray = [[_breedsArray filteredArrayUsingPredicate:predicate] mutableCopy];
return YES;
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
// Tells the table data source to reload when scope bar selection changes
[_filteredBreedsArray removeAllObjects];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",self.searchDisplayController.searchBar.text];
_filteredBreedsArray = [[_breedsArray filteredArrayUsingPredicate:predicate] mutableCopy];
return YES;
}
我完全按照教程做的,可是每次我在搜索栏输入文本,它就报错:
2013-01-07 19:47:07.330 FindFeedo[3206:c07] *** Assertion failure in -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460
2013-01-07 19:47:07.330 FindFeedo[3206:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier BreedCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
解决方法 1:
在dequeueReusableCellWithIdentifier里试着用self.tableView代替tableVie:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"BreedCell"];
//Create PetBreed Object and return corresponding breed from corresponding array
PetBreed *petBreed = nil;
if(tableView == self.searchDisplayController.searchResultsTableView)
petBreed = [_filteredBreedsArray objectAtIndex:indexPath.row];
else
petBreed = [_breedsArray objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = petBreed.name;
return cell;
}
注意:
如果你有个自定义高度的cells,不要用:
[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
用这个代替:
[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- ios在UITableViewController里使用UISearchDisplayController报错"[UISearchResultsTableView dequeueReusableCel
- 在IOS 7中使用UITableViewController
- IOS UISearchBar + UISearchDisplayController使用
- iOS之UISearchDisplayController的使用
- iOS之UITableViewController的使用
- iOS UITableViewController基本使用简述
- iOS - UITableViewController的RefreshControl使用
- UISearchDisplayController搜索时总是报cell错
- iOS开发-UI控件:关于使用UISearchDisplayController
- iOS UISearchBar 和 UISearchDisplayController的使用
- ios 在UITableViewController上添加悬浮视图
- iOS UITableViewController
- IOS中UITableViewController使用注意点
- uisearchDisplayController放在tableview里下拉刷新状态出现遮挡
- 在okHttp里使用Gson解析 报错OKHttp Dispatcher
- storyboard : 在 UITableViewController 中使用自定义
- navigationItem和tableView在UITableViewController里的关系
- UITableViewController使用
- jdbc增删改查操作 存储过程
- 可空类型Nullable到底是什么鬼
- 微信小程序全套使用指南
- task_struct结构体成员详解
- PAT乙级1031
- ios在UITableViewController里使用UISearchDisplayController报错"[UISearchResultsTableView dequeueReusableCel
- 纪录片:互联网之子 亚伦·斯沃茨的故事
- linux 系统下如何进行用户之间的切换
- maven的使用
- 命令行输出php 并传递参数
- Android常见问题之三
- java.sql.SQLException: ORA-00911: 无效字符 解决方法
- JavaScript定时器原理分析
- 《重构》-2-重构原则-读书笔记