2013-04-17 64 views
0

我不明白這一點:我的cellForRowAtIndexPath:indexPath:返回一個適當的UITableViewCell。 (我有一個斷言,這不是零的效果和跟蹤,以證明這一點)UITableView dataSource必須從tableView返回一個單元格:cellForRowAtIndexPath:但我做

但我還是老樣子得到這個零星的例外?

我這是怎麼分配/複用單元:

... 
{ 
    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier: cellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault 
            reuseIdentifier: cellIdentifier] autorelease]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    assert(cell); 
    // (code to populate cell) 
    // ... 
    assert(cell != nil); 
    NSLog(@"returning cell %@ type %@", cell, NSStringFromClass([cell class])); 
    // edit: showing actual return value 
    return cell; 
} 

崩潰,看起來像這樣在日誌中:

2013-04-17 16:46:05.323 .. -[SomeEditViewController tableView:cellForRowAtIndexPath:] returning cell <UITableViewCell: 0x20d1a2e0; frame = (0 351; 320 43); hidden = YES; autoresize = W; layer = <CALayer: 0x20d1a410>> type UITableViewCell 
2013-04-17 16:46:15.296 ... *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit/UIKit-2380.17/UITableView.m:5471 
2013-04-17 16:46:15.301 ... *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 

我已經看過無數的其他條目有類似的問題。我很難過!我做了功課,確保我返回的細胞不是零,我仍然得到這個斷言!

任何人都可以提供幫助嗎? 感謝

+2

顯示包含'return cell;'調用的完整'cellForRowAtIndexPath'。 – rmaddy

回答

0

事實證明,我確實回來了之後的所有細胞(儘可能的cellForRowAtIndexPath:關注)

問題是由在dealloc的分配tableView.datasource和tableView.delegate爲零解決。

當容器視圖控制器被釋放時,表視圖最有可能仍然處於dealloc狀態,並且它無法調用我的cellForRowAtIndexPath實現。 至少,我能夠重現問題(和修復)。

相關問題