I have tableview
使用搜索结果控制器在搜索栏中搜索时收到此错误表明没有单元格并收到以下错误。如何创建我的prototype
该方法中的细胞CellForRowAtIndexPath
Code :
- (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;
}
Error :
*** 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)您返回的数字大于您的数组计数
表视图:numberOfRowsInSection:。不。
2) 您的一个或多个手机#插座未连接到您的笔尖,或者
没有连接到 UITableViewCell (或子类)。把它们挂起来
适当地。
经历这个雷·温德利希的链接:
检查这个所以问题:
1) UITableView dataSource 必须从 tableView 返回一个单元格:cellForRowAtIndexPath:异常 https://stackoverflow.com/questions/2224316/uitableview-datasource-must-return-a-cell-from-tableviewcellforrowatindexpath
2) ios 5 UISearchDisplayController 崩溃 https://stackoverflow.com/questions/8066668/ios-5-uisearchdisplaycontroller-crash
另一个漂亮的链接:自定义原型表格单元和故事板 http://useyourloaf.com/blog/2012/06/07/prototype-table-cells-and-storyboards.html就看这个部分 :
- (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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)