【问题标题】:Custom cell error when reload searchResultsTableView重新加载 searchResultsTableView 时自定义单元格错误
【发布时间】:2011-11-01 03:18:36
【问题描述】:

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

如果我写下搜索词并单击搜索按钮,则数据将填充到 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] * 断言失败 -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2011-10-31 20:56:53.159 TheBE[1207:10403] 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath 返回一个单元格:' ** 首先抛出调用堆栈: (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) P>


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)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)mockSearch:(NSString*)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)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ [自我模拟搜索:searchBar.text]; }

我认为错误部分:

[self.searchDisplayController.searchResultsTableView reloadData];

【问题讨论】:

标签: ios uitableview ios5 xcode4.2 uisearchdisplaycontroller


【解决方案1】:

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

【讨论】:

  • 你是对的。 [tableView:cellForRowAtIndexPath], [dequeueReusableCellWithIdentifier:] 返回 nil。所以我添加了代码 。但是单元格返回零。我找不到原因。
  • 编辑您的问题并将代码放在那里,格式正确。
【解决方案2】:

我有同样的错误。我认为这是因为调整某些按钮属性意味着需要设置视图(显然是懒惰创建的),这意味着表需要准备好,但还没有,可能是因为它的数据源尚未连接或者其他的东西。尝试在 viewDidLoad 方法中将按钮调整移到后面;这对我有用。

(另见UITableView getting Initialized in the middle of viewDidLoad?,我在其中发布了相同的答案。)

【讨论】:

    【解决方案3】:

    故事板中的自定义单元格,而不是“self.searchDisplayController.searchResultsTableView”中,所以只需更改:

    SearchContentCell *cell = (SearchContentCell *)[ -->tableView

    到

    SearchContentCell *cell = (SearchContentCell *)[ -->self.tableView

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 1970-01-01
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多