0
排序PFObjects數組我有PFUsers的數組,我想基於本地搜索結果對其進行過濾:通過用戶名
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"username contains[cd] %@",
searchText];
_searchResults = [[_messages filteredArrayUsingPredicate:resultPredicate] mutableCopy];
NSLog(@"_searchResults: %@",_searchResults);
}
但是,這並不工作,並最終產生了以下錯誤:
'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
有人知道我的NSPredicate有什麼問題嗎?謝謝!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell;
if (cell == nil) {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSLog(@"here?");
cell.textLabel.text = [_searchResults objectAtIndex:indexPath.row];
} else {
UILabel *name = (UILabel *)[cell viewWithTag:101];
if (_messages.count == 0)
name.text = @"No Messages";
else
name.text = @"name";
}
return cell;
}
我不認爲NSPredicate過濾器的工作,但...
我想這不是'NSPredicate'錯誤,你能顯示你的'tableView:cellForRowAtIndexPath'方法嗎? –
你沒有提供足夠的信息。您發佈了將數組過濾到結果數組中的代碼塊。這與你的表格視圖數據源有什麼關係?你需要提供更多關於你在做什麼的信息,特別是發佈你的cellForRowAtIndexPath方法,就像@Virussmca所說的那樣。 –
@Virussmca編輯 – Apollo