我在我的 tableview 控制器的 viewWillAppear() 中调用以下方法来加载我想要显示的数据的静态单元格。第 1 节和第 2 节显示正确。第 3 节根本不加载。但是,当我将情节提要中的 tableview 设置从分组更改为普通时,第 2 节中的第一个单元格正确显示。在我看来,当视图出现在屏幕上时最初不可见的单元格没有正确加载。
-(void)loadCells
{
UITableViewCell *cell = [[UITableViewCell alloc] init];
//Section 0
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
cell.textLabel.text = ...;
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
cell.textLabel.text = ...;
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
cell.textLabel.text = ...;
// Section 1
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
cell.textLabel.text = ...;
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
cell.textLabel.text = ...;
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:1]];
cell.textLabel.text = ...;
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:1]];
cell.textLabel.text = ...;
// Section 2
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];
cell.textLabel.text = @"Testing";
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:2]];
cell.textLabel.text = ...;
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:2]];
cell.textLabel.text = ...;
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:2]];
cell.textLabel.text = ...;
cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:2]];
cell.textLabel.text = ...;
}