gpt4 book ai didi

iphone - 我如何在带有搜索结果 Controller 的 Storyboard 中使用原型(prototype)单元

转载 作者:可可西里 更新时间:2023-11-01 05:41:47 29 4
gpt4 key购买 nike

当在搜索栏中搜索时,我有带有搜索结果 Controller 的 tableview 出现此错误,表明没有单元格并出现以下错误。如何创建我的 prototype 单元格在这个方法中 CellForRowAtIndexPath

代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
static NSString *CellIdentifier = @"HoCell";
Ho *cell;
Ho *item;

if (tableView == self.searchDisplayController.searchResultsTableView) {
if (cell == nil)
{
cell = [[Ho alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"HoCell"];
}
item = [searchResultsController objectAtIndexPath:indexPath];
}
else{
cell = (Ho*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
item = [fetchedResultsController objectAtIndexPath:indexPath];
}
cell.ho.text = item.name;

cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"se.png"]];

return cell;
}

错误:

*** Assertion failure in -[UISearchResultsTableView _configureCellForDisplay:forIndexPath:],  /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:5471
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

最佳答案

这里可能有两种可能:

1) You are returning a number larger than your Array Count from tableView:numberOfRowsInSection:. Don't.

2) One or more of your cell# outlets is not hooked up in your nib, or is not hooked up to a UITableViewCell (or subclass). Hook them up properly.

通过这个 Ray Wenderlich 的链接: How to Add Search Into a Table View

检查此SO 问题:

1) UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath: Exception

2) ios 5 UISearchDisplayController crash

一个更漂亮的链接:Custom Prototype Table Cells and Storyboards看看这个部分:

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:UYLCountryCellIdentifier];
if (cell == nil)
{
[self.countryCellNib instantiateWithOwner:self options:nil];
cell = self.countryCell;
self.countryCell = nil;
}
// Code omitted to configure the cell...
return cell;
}

关于iphone - 我如何在带有搜索结果 Controller 的 Storyboard 中使用原型(prototype)单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14191841/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com