问题描述
我正在 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 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)