我UIViewController在故事板中设置了一个tableview和UISearchDisplayController.
我正在尝试使用self.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;
}
Run Code Online (Sandbox Code Playgroud)
错误:
*** 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 …Run Code Online (Sandbox Code Playgroud) iphone objective-c uitableview uisearchdisplaycontroller ios