iOS-UITableView在numberOfRowsInSection:和cellForRowAtIndexPath:方法之间工作不正确

iOS-UITableView在numberOfRowsInSection:和cellForRowAtIndexPath:方法之间工作不正确,ios,uitableview,Ios,Uitableview,我在UIView中创建了一个UITableView,只使用代码而不使用IB m_tableData = [[UITableView alloc] init]; m_tableData.dataSource = self; m_tableData.delegate = self; [self addSubview:m_tableData]; 及 } 在日志屏幕中我看到 numberOfRowsInSection:方法返回18。 方法,只需在屏幕中运行9次 我在我的代码中没有发现任

我在UIView中创建了一个UITableView,只使用代码而不使用IB

 m_tableData = [[UITableView alloc] init];
 m_tableData.dataSource = self; 
 m_tableData.delegate = self;   
 [self addSubview:m_tableData];

}

在日志屏幕中我看到

numberOfRowsInSection:方法返回18。 方法,只需在屏幕中运行9次

我在我的代码中没有发现任何奇怪的东西。所以在这种情况下,任何人都可以给我任何建议。 感谢高级版。

您需要使用UITableView的initWithFrame:style:method-这是UITableView类的指定初始值设定项。

您的意思是

m_tableData = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
当我改变它时,与我原来的结果没有什么不同。这真的很奇怪,这是我第一次看到这个错误,仍然没有解决办法

编辑:
-只需删除检查条件单元格==nil并正常工作。

这应该是正确的。在需要显示数据之前,它不会要求您用数据填充单元格。
m_tableData = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];