如何在故事板中使用原型单元与搜索结果控制器 [英] How can i use prototype cell in storyboard with search result controller

查看:94
本文介绍了如何在故事板中使用原型单元与搜索结果控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有搜索结果控制器的 tableview 在搜索栏中搜索得到此错误表示没有单元格并得到以下错误。如何创建我的 prototype 此方法中的单元格 CellForRowAtIndexPath

I have tableview with search result controller when search in search bar get this error indicate that there is no cell and get the below error .How can create my prototype cell in this method 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:'


推荐答案

这里可能有两种可能性:

There may be two possibilities Here :


1)从$返回的数字大于数组计数b $ b tableView:numberOfRowsInSection:。不要。

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

2)你的一个或多个单元格#outlet没有连接到你的笔尖,或者
没有连接到UITableViewCell(或子类)。正确地将它们挂钩

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的链接:
如何将搜索添加到表视图中

选中 SO问题:

1) UITableView dataSource必须从tableView返回一个单元格:cellForRowAtIndexPath:Exception

2) ios 5 UISearchDisplayController崩溃

一个更美丽的链接:自定义原型表格单元和故事板看到这个部分:

One More Beautiful Link : Custom Prototype Table Cells and Storyboards Just see this Portion :

- (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;
}

这篇关于如何在故事板中使用原型单元与搜索结果控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆