静态表格视图 - 最初不在屏幕上的单元格不更新
Posted
技术标签:
【中文标题】静态表格视图 - 最初不在屏幕上的单元格不更新【英文标题】:static tableview - cells initially off screen not updating 【发布时间】:2013-05-11 04:02:03 【问题描述】:我在我的 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 = ...;
【问题讨论】:
【参考方案1】:这不是用静态单元格填充表格视图的方法。您应该将 IBOutlets 设置为表格视图控制器中的标签,然后以正常方式设置标签的值。
【讨论】:
谢谢 - 非常感谢。工作并且很干净。以上是关于静态表格视图 - 最初不在屏幕上的单元格不更新的主要内容,如果未能解决你的问题,请参考以下文章