***声明失败 –

我在我的项目中使用tableview苹果的延迟加载代码,但在项目中有exception。 而错误是 – *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:] ,这里是我的代码请help.But它在其他项目中工作。我没有委托方法。

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"LazyTableCell"; static NSString *PlaceholderCellIdentifier = @"PlaceholderCell"; NSUInteger nodeCount = [self.entries count]; if (nodeCount == 0 && indexPath.row == 0) { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier]; cell.detailTextLabel.text = @"Loading…"; return cell; } UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (nodeCount > 0) { AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row]; cell.textLabel.text = appRecord.name; if (!appRecord.appIcon) { if (self.mytable_view.dragging == NO && self.mytable_view.decelerating == NO) { [self startIconDownload:appRecord forIndexPath:indexPath]; } cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"]; } else { cell.imageView.image = appRecord.appIcon; } } return cell; } 

因为cellForRowAtIndexPath返回一个nil值,然后configureCellForDisplay期待一个UITableViewCell 。 故事板或XIB没有用您指定的单元格标识符定义的单元格。 更好地检查标识符的拼写。

请检查代表。

你是否添加了两个委托?

UITableViewDelegateUITableViewDataSource

 import UIKit class UserFriendVC: UIViewController, UITableViewDelegate, UITableViewDataSource { override func viewDidLoad() { super.viewDidLoad() } } 

你应该从“显示属性检查器”添加cellIdentifier。 请像下面的片段一样休闲。

首先将下面的代码添加到你的-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath delagate方法。

 -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ ResultCustomTableViewCell *cell = (ResultCustomTableViewCell *)[resultTableView dequeueReusableCellWithIdentifier:@"ResultTableViewCellIdentifier"]; ... //set the cell property ... return cell; } 

然后跳转“显示属性检查器”,同时选中单元格根视图。

在这里输入图像说明

然后在“显示属性检查器”中将相同的标识符名称粘贴到标识符部分。 在这种情况下,我使用这个ResultTableViewCellIdentifier。

还有一个想法。 如果您使用自定义单元格就像这种情况下,您必须添加下面的委托metod。 因为您的自定义单元格高度可以更高或更小的原始tableview高度。 而且你也应该在viewDidLoad中注册这个笔尖。

  - (void)viewDidLoad { [resultTableView registerNib:[UINib nibWithNibName:@"ResultCustomTableViewCell" bundle:nil] forCellReuseIdentifier:[ResultCustomTableViewCell reuseIdentifier]]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ CGFloat height = 0.0; if (tableView == resultTableView){ height = 44.0f; } return height; } 

我希望它能解决你的问题

CellIdentifier我打赌你的cellForRowAtIndexPath返回零。

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"LazyTableCell"; static NSString *PlaceholderCellIdentifier = @"PlaceholderCell"; NSUInteger nodeCount = [self.entries count]; if (nodeCount == 0 && indexPath.row == 0) { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PlaceholderCellIdentifier] autorelease]; } cell.detailTextLabel.text = @"Loading…"; return cell; } UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } if (nodeCount > 0) { AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row]; cell.textLabel.text = appRecord.name; if (!appRecord.appIcon) { if (self.mytable_view.dragging == NO && self.mytable_view.decelerating == NO) { [self startIconDownload:appRecord forIndexPath:indexPath]; } cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"]; } else { cell.imageView.image = appRecord.appIcon; } } return cell; } 

这可能是为什么[UITableView _configureCellForDisplay:forIndexPath:]失败…因为cellForRowAtIndexPath返回一个空值,然后configureCellForDisplay期待一个UITableViewCell