如何填充一个静态的UITableView
我尝试了几种方法,但似乎我失去了一些东西..
这是我使用的代码:
- (void)configureView { // Update the user interface for the detail item. if (self.detailItem) { for (int idx=0; idx<16; idx++) { NSIndexPath *indexPath = [[NSIndexPath alloc] initWithIndex:idx]; [self.tableView cellForRowAtIndexPath:indexPath].detailTextLabel.text = [param objectAtIndex:idx]; } self.detailDescriptionLabel.text = [self.detailItem description]; } }
我在viewDidLoad上调用这个。 我的tableview有16静态单元格,我使用标准的“小标题”types单元格,所以没有定制需要在这方面。 textLabel.text在devise时被填充。 此外我的tableview是在tableViewController。 我也尝试了标准的tableview人口,但似乎静态单元格不同意这种方式。
我究竟做错了什么?
@jrturton我做了一些改变,看看发生了什么事情:
我把这三行加在一行看看有没有什么:
UITableView *tv = self.tableView; UITableViewCell *cell = [tv cellForRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:0]]; NSString *label = [[NSString alloc] initWithString:cell.textLabel.text];
首先电视分配正确,我可以看到。 但除此之外,单元格和标签都是空的。 即使电视没有行信息,似乎..
难道是因为tableview的数据源和委托分配给tableviewcontroller ..我想我听说它不应该是这样或某事…
@ jrturton这里是:
希望这可以帮助。
一些日志会快速显示您的索引path无效,因此没有单元格被返回。
要创build在UITableView中使用的NSIndexPath,请使用以下方法:
[NSIndexPath indexPathForRow:idx inSection:0];
索引path必须包含表格的行和部分来理解它。
你还需要从viewWillAppear:
调用它viewWillAppear:
而不是viewDidLoad,静态表在早期不会被填充。 你必须先调用[super viewWillAppear:animated]
!