【发布时间】:2012-03-08 11:38:06
【问题描述】:
我正在使用一个简单的搜索显示控制器。我收到这个错误,我不知道。这是代码请帮助n谢谢!!!!!!
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger rows = 0;
if([tableView isEqual:self.searchDisplayController.searchResultsTableView])
{
rows = [self.searchResults count];
}
else
{
rows = [self.allItems count];
}
return rows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if([tableView isEqual:self.searchDisplayController.searchResultsTableView])
{
cell.textLabel.text = [self.searchResults objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.text = [self.allItems objectAtIndex:indexPath.row];
}
return cell;
NSLog(@"the contents of cell are :%@",cell.textLabel.text);
}
-(void) filterContentsForSearchText:(NSString *)searchText scope:(NSString *)scope
{
NSPredicate *resultsPredicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@",searchText];
self.searchResults = [self.allItems filteredArrayUsingPredicate:resultsPredicate];
}
//UISearchDisplayController delegate methods
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentsForSearchText:searchString scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex: [self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
-(BOOL)searchDisplayController:(UISearchDisplayController *) controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentsForSearchText:[self.searchDisplayController.searchBar text] scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
return YES;
}
错误如下:
2012-03-08 15:37:18.905 SearchViewController[1082:fe03] * -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 中的断言失败 2012-03-08 15:37:18.907 SearchViewController[1082:fe03] * 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath: 返回一个单元格:”
【问题讨论】:
-
您找到解决问题的方法了吗?我遇到了类似的问题,我真的认为那是因为我没有正确地将原型单元格与 searchResultsTableView 链接
标签: objective-c uitableview ios5 uisearchbar