Ios UITababVIEW在VIEW DIDEAD加载过程中初始化?

Ios UITababVIEW在VIEW DIDEAD加载过程中初始化?,ios,uitableview,viewdidload,Ios,Uitableview,Viewdidload,我有一个正在初始化的VC,其中有一个视图。在视图中是一个ui表格视图、ui按钮和ui图像 我正在搞乱按钮属性,突然,砰: Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] 经过进一步挖掘,这是因为我的代码: UINib *animCellNib = [UINib nibWithNibName:@"IoUISEAnimationDetailListingCell" bundle:n

我有一个正在初始化的VC,其中有一个
视图
。在
视图中
是一个
ui表格视图
ui按钮
ui图像

我正在搞乱按钮属性,突然,砰:

Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]
经过进一步挖掘,这是因为我的代码:

UINib *animCellNib = [UINib nibWithNibName:@"IoUISEAnimationDetailListingCell" bundle:nil];
[animationDetailsTableView registerNib:animCellNib forCellReuseIdentifier:@"AnimationDetailListingCell"];
没有被处决。进一步挖掘显示在我的
viewDidLoad
方法的顶部,它开始初始化
tableView
。因此,从我的方法名跟踪中,您可以看到它以
numberOfSectionsInTableView
开头。虽然这只发生在我的
viewDidLoad

2011-10-12 15:43:42.113 io[5052:11903] <IoUISEAnimationDetailsViewController: 0x764c460> - initWithNibName:bundle:
2011-10-12 15:43:42.116 io[5052:11903] <IoUISEAnimationDetailsViewController: 0x764c460> - viewDidLoad
Current language:  auto; currently objective-c
2011-10-12 15:43:49.017 io[5052:11903] <IoUISEAnimationDetailsViewController: 0x764c460> - numberOfSectionsInTableView:
2011-10-12 15:43:49.017 io[5052:11903] <IoUISEAnimationDetailsViewController: 0x764c460> - tableView:titleForHeaderInSection:
2011-10-12 15:43:49.017 io[5052:11903] <IoUISEAnimationDetailsViewController: 0x764c460> - tableView:titleForFooterInSection:
2011-10-12 15:43:49.017 io[5052:11903] <IoUISEAnimationDetailsViewController: 0x764c460> - tableView:numberOfRowsInSection:
2011-10-12 15:43:49.017 io[5052:11903] <IoUISEAnimationDetailsViewController: 0x764c460> - tableView:cellForRowAtIndexPath:
2011-10-12 15:43:49.017 io[5052:11903] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072
2011-10-12 15:43:49.018 io[5052:11903] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
在此方法中,
dequeueReusableCellWithIdentifier:
返回nil。找不到AnimationDetailListingCell标识符,因为
viewDidLoad
中的
RegisterInB
代码尚未运行。似乎所有的
viewDidLoad
都应该在初始化tableview之前运行,对吗

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (IoUIDebug & IoUIDebugSelectorNames) {
    NSLog(@"%@ - %@", [self description], NSStringFromSelector(_cmd) );
}
UITableViewCell *cell;

cell = [animationDetailsTableView dequeueReusableCellWithIdentifier:@"AnimationDetailListingCell"];
// cell at this point in nil!

[self configureCell:cell atIndexPath:indexPath];

return cell;
}

我也犯了同样的错误。我认为这是因为调整某些按钮属性意味着需要设置视图(显然是延迟创建的),这意味着表需要准备就绪,而它还没有准备就绪,可能是因为它的数据源尚未连接或其他原因。尝试将按钮调整移动到viewDidLoad方法的后面;这对我起了作用。

我相信这就是我最终所做的。我得回去看看,好像是在很久以前(在编码年代里)(;我也遇到了这个错误,当我找到它时,那是因为在我的CellForRowAtIndexPath中有一个案例,我可以返回nil。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (IoUIDebug & IoUIDebugSelectorNames) {
    NSLog(@"%@ - %@", [self description], NSStringFromSelector(_cmd) );
}
UITableViewCell *cell;

cell = [animationDetailsTableView dequeueReusableCellWithIdentifier:@"AnimationDetailListingCell"];
// cell at this point in nil!

[self configureCell:cell atIndexPath:indexPath];

return cell;
}