gpt4 book ai didi

ios5 - ios 5 UISearchDisplayController 崩溃

转载 作者:行者123 更新时间:2023-12-03 10:44:10 25 4
gpt4 key购买 nike

我正在 xcode 4.2 中使用 UISearchDisplayController 实现 UITableView。
UITableView 和 UISearchDisplayController 在 StoryBoard 中创建。
我为 UITableView 设置了 Cell Identifier (SampleCell) 并像访问它一样访问它

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

UItableView 工作正常。
但是一旦我尝试搜索,应用程序就会崩溃并显示以下错误。
*** 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 单元格设置单元格标识符。
但我不知道怎么做。
在此先感谢您的帮助。 =)

最佳答案

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

您尝试出列的单元格链接到主 View Controller 的 tableView在 Storyboard中,而不是 searchDisplayController的新创建 tableView (它没有链接到单元格标识符)。如果您只是发送消息“tableView ”,那么您的出队消息将发送至 searchDisplayController's tableView 因为那是传递给 cellForRowAtIndexPath: 的内容... 方法。

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

// do your thing

return cell;
}

关于ios5 - ios 5 UISearchDisplayController 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8066668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com