ios 5 UISearchDisplayController 崩溃 [英] ios 5 UISearchDisplayController crash

查看:17
本文介绍了ios 5 UISearchDisplayController 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 xcode 4.2 中使用 UISearchDisplayController 实现 UITableView.UITableView &UISearchDisplayController 是在 StoryBoard 中创建的.我为 UITableView 设置单元格标识符(SampleCell)并像访问它一样

I am implementing a UITableView with UISearchDisplayController in xcode 4.2. UITableView & UISearchDisplayController are created in StoryBoard. I set the Cell Identifier (SampleCell) for UITableView and access it like

cell = [tableView dequeueReusableCellWithIdentifier:@"SampleCell"];

UItableView 工作正常.但是一旦我尝试搜索,应用程序就会崩溃并出现以下错误.

UItableView is working fine. But once i try to search, the app crash with below error.

*** Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072
2011-11-09 22:22:16.058 SampleApp[14362:fb03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

我想我需要为 self.searchDisplayController.searchResultsTableView 单元格设置单元格标识符.但我不知道怎么做.提前感谢您的帮助.=)

I guess I need to set the cell identifier for self.searchDisplayController.searchResultsTableView cell. But I don't know how. Thanks in advance for any help. =)

推荐答案

使用[self.tableView dequeue...],而不是[tableView dequeue...].

您尝试出列的单元格链接到情节提要中主视图控制器的 tableView,而不是 searchDisplayController 新创建的 tableView (没有链接到它的单元格标识符).如果您只是发送消息tableView",那么您的出队消息将发送到 searchDisplayController's tableView,因为这是传递给 cellForRowAtIndexPath:... 方法的内容.

The cell you're trying to dequeue is linked to your primary view controller's tableView in the storyboard, NOT the searchDisplayController's newly created tableView (which has no cell identifiers linked to it). If you just message "tableView" then your dequeue message goes to the searchDisplayController's tableView since that's what was passed into the cellForRowAtIndexPath:... method.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CellId"];

    // do your thing

    return cell;
}

这篇关于ios 5 UISearchDisplayController 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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