ios 5 UISearchDisplayController crash(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 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ios 5 UISearchDisplayController 崩溃
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
