• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 重新加载 searchResultsTableView 时自定义单元格错误

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:37:44 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

当我点击这个按钮-[搜索]时,弹出窗口。

如果我写下搜索词并单击搜索按钮,则数据将填充到 NSMutableArray 中。

此 searchTable 使用“自定义单元格”。

我无法将“自定义单元格”与 NSMutableArray 中的数据结合起来。

重新加载“searchTableView”时出现错误。

我该怎么办?请帮帮我!~谢谢~

[错误]

2011-10-31 20:56:52.915 TheBE[1207:10403] abcd 2011-10-31 20:56:53.158 TheBE[1207:10403] * Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2011-10-31 20:56:53.159 TheBE[1207:10403] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' ** First throw call stack: (0x12a2052 0x1753d0a 0x124aa78 0xc712db 0x381ee3 0x382589 0x36ddfd 0x37c851 0x327322 0x12a3e72 0x29ba92d 0x29c4827 0x294afa7 0x294cea6 0x294c580 0x12769ce 0x120d670 0x11d94f6 0x11d8db4 0x11d8ccb 0x1fae879 0x1fae93e 0x2e8a9b 0x1d68 0x1cc5 0x1)


<上一页> -(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath { //******自定义单元格*********/ SearchContentCell *cell = (SearchContentCell *)[tableView dequeueReusableCellWithIdentifier"SearchCell"]; [cell.contentLabel setLineBreakMode:UILineBreakModeWordWrap]; [cell.contentLabel setMinimumFontSize:FONT_SIZE]; [cell.contentLabel setNumberOfLines:0]; [cell.contentLabel setFont:[UIFont systemFontOfSize:FONT_SIZE]]; [cell.contentLabel setTag:1]; ………… cell.verseLabel.text = @"Test2"; cell.contentLabel.text = @“测试”; ………… 返回单元格; } -(void)mockSearchNSString*)searchString { [_data removeAllObjects]; [请求设置实体:实体圣经]; // //创建谓词 NSString *wildcardedString = [NSString stringWithFormat"*%@*",searchString]; NSPredicate *predicate = [NSPredicate predicateWithFormat"content like %@", wildcardedString]; [请求集合谓词:谓词]; NSError *错误; NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy]; if (mutableFetchResults == nil) { //处理错误; NSLog(@"eerror"); } _data = mutableFetchResults; [self.searchDisplayController.searchResultsTableView reloadData]; } -(void)searchBarSearchButtonClickedUISearchBar *)searchBar{ [ self 模拟搜索:searchBar.text]; }

我认为错误部分:

[self.searchDisplayController.searchResultsTableView reloadData];



Best Answer-推荐答案


如果这确实是您的 tableView:cellForRowAtIndexPath: 方法的样子,那么如果 dequeueReusableCellWithIdentifier: 返回 nil,您将丢失分配新单元格的部分。

关于ios - 重新加载 searchResultsTableView 时自定义单元格错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7962107/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap