【发布时间】:2012-06-06 11:42:38
【问题描述】:
我有一个UITableViewController,它的UITableView 是静态的,包含三个部分。我正在尝试在viewWillAppear 中填充我的静态部分,如下所示:
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] detailTextLabel] setText:@"Stuff"];
[[[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]] detailTextLabel] setText:@"Other stuff"];
...
}
第一行很好地填充了第 0 行中的第 0 行,但第二行(实际上是对除第一行之外的任何部分的任何 cellForRowAtIndexPath 调用)返回一个 nil 单元格。
我做了一些测试来尝试缩小问题范围:
[self.tableView numberOfSections] // returns 3 - which is correct
[self.tableView numberOfRowsInSection:1] // return 4 - which is unique and correct for my second section
所以,表格视图的部分看起来是正确的,但是:
[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] // nil
我很困惑 - 有人知道可能是什么原因造成的吗?
我的代码没有什么特别之处:它是在故事板中创建的一个简单的静态表,从一开始就设置了所有三个部分;视图控制器正确地是 UITableViewController 的子类;我可以完美地填充第 0 部分,并且一切正常。
感谢您的帮助。
【问题讨论】:
-
您确实需要滚动才能看到第二和第三部分,是的。
-
谢谢。我现在就试试。
-
@jrturton 使用网点效果很好。非常感谢您的帮助。
标签: ios objective-c iphone xcode