轉:Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]

weixin_30588675發表於2020-04-05
Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]
今天做一個tableView遇到一個這麼個問題。
經過baidu google,終於找到正解。
因為
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
這個函式的返回值是個null!!
查stackoverflow 找到下面的解。
CellIdentifier I bet your cellForRowAtIndexPath is returning null.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *CellIdentifier = @"Photos";

    /** NOTE: This method can return nil so you need to account for that in code */
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // NOTE: Add some code like this to create a new cell if there are none to reuse
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    NSString *string = [[self.photosInPlace objectAtIndex:indexPath.row]     valueForKeyPath:@"description._content"];

    cell.textLabel.text = string;

    return cell;
}
That's probably why [UITableView _configureCellForDisplay:forIndexPath:] is failing... becausecellForRowAtIndexPath is returning a null value and then configureCellForDisplay is expecting aUITableViewCell.

轉:http://blog.csdn.net/theonezh/article/details/8613593

轉載於:https://www.cnblogs.com/ygm900/archive/2013/06/13/3134425.html

相關文章