OGeek|极客世界-中国程序员成长平台

标题: ios - 重新加载 searchResultsTableView 时自定义单元格错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:37
标题: ios - 重新加载 searchResultsTableView 时自定义单元格错误

当我点击这个按钮-[搜索]时,弹出窗口。

如果我写下搜索词并单击搜索按钮,则数据将填充到 NSMutableArray 中。

此 searchTable 使用“自定义单元格”。

我无法将“自定义单元格”与 NSMutableArray 中的数据结合起来。

重新加载“searchTableView”时出现错误。

我该怎么办?请帮帮我!~谢谢~

[错误]

2011-10-31 20:56:52.915 TheBE[1207:10403] abcd 2011-10-31 20:56:53.158 TheBE[1207:10403] * Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2011-10-31 20:56:53.159 TheBE[1207:10403] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' ** First throw call stack: (0x12a2052 0x1753d0a 0x124aa78 0xc712db 0x381ee3 0x382589 0x36ddfd 0x37c851 0x327322 0x12a3e72 0x29ba92d 0x29c4827 0x294afa7 0x294cea6 0x294c580 0x12769ce 0x120d670 0x11d94f6 0x11d8db4 0x11d8ccb 0x1fae879 0x1fae93e 0x2e8a9b 0x1d68 0x1cc5 0x1)


<上一页> -(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath { //******自定义单元格*********/ SearchContentCell *cell = (SearchContentCell *)[tableView dequeueReusableCellWithIdentifier"SearchCell"]; [cell.contentLabel setLineBreakMode:UILineBreakModeWordWrap]; [cell.contentLabel setMinimumFontSize:FONT_SIZE]; [cell.contentLabel setNumberOfLines:0]; [cell.contentLabel setFont:[UIFont systemFontOfSize:FONT_SIZE]]; [cell.contentLabel setTag:1]; ………… cell.verseLabel.text = @"Test2"; cell.contentLabel.text = @“测试”; ………… 返回单元格; } -(void)mockSearchNSString*)searchString { [_data removeAllObjects]; [请求设置实体:实体圣经]; // //创建谓词 NSString *wildcardedString = [NSString stringWithFormat"*%@*",searchString]; NSPredicate *predicate = [NSPredicate predicateWithFormat"content like %@", wildcardedString]; [请求集合谓词:谓词]; NSError *错误; NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; if (mutableFetchResults == nil) { //处理错误; NSLog(@"eerror"); } _data = mutableFetchResults; [self.searchDisplayController.searchResultsTableView reloadData]; } -(void)searchBarSearchButtonClickedUISearchBar *)searchBar{ [ self 模拟搜索:searchBar.text]; }

我认为错误部分:

[self.searchDisplayController.searchResultsTableView reloadData];



Best Answer-推荐答案


如果这确实是您的 tableView:cellForRowAtIndexPath: 方法的样子,那么如果 dequeueReusableCellWithIdentifier: 返回 nil,您将丢失分配新单元格的部分。

关于ios - 重新加载 searchResultsTableView 时自定义单元格错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7962107/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4