我UIViewController
在情节提要中有一个带有tableview
和的设置UISearchDisplayController
。
我正在尝试使用 self.tableview 中的自定义原型单元(它连接到情节提要中的主 tableview)。self.tableview
如果在我加载视图时返回了至少 1 个单元格,它工作正常,但如果self.tableview
没有加载单元格(因为没有数据),并且我加载UISearchBar
并搜索,该cellForRowAtIndexPath:
方法崩溃:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomSearchCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomSearchCell" forIndexPath:indexPath];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
-(void)configureCell:(CustomSearchCell *)cell atIndexPath:(NSIndexPath *)indexPath {
User *user = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.nameLabel.text = user.username;
}
错误:
*** Assertion failure in -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath: 0x9ef3d00> {length = 2, path = 0 - 0})
在调用上述方法时,我的 fetchedResultsController 似乎有数据(1 节,2 行)。它在线上崩溃dequeueReusableCellWithIdentifier
。
任何指针/想法?它应该将原型单元格从中出列self.tableview
,但我猜没有在其中创建,self.tableview
所以这是原因吗?