好的,经过几次尝试,我终于在@jrturton的帮助下填充了静态表格视图(如何填充静态 UITableView)。
但是现在我遇到了另一个问题。似乎在填充字段时,通过我使用的方法仅填充了可见字段。通过代码填充的其他字段在向下滚动时保持为空。
有什么我想念的吗?虽然通过委托填充动态表格肯定会解决我看到的问题,但我只是不想通过数组等填充所有静态文本(标签)。而且我知道表格中总会有 16 行。
所以有人对出了什么问题有任何建议吗?
这是代码:
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
}
}
-(void)setParam:(id)newparam
{
if (_param != newparam) {
_param = newparam;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (_detailItem) {
for (int idx=0; idx<16; idx++) {
NSString *value = [NSString stringWithFormat:@"%@",[_param objectAtIndex:idx]];
[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:0]].detailTextLabel.text = value;
}
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Do any additional setup after loading the view, typically from a nib.
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self configureView];
}
我从早期的代码中修改了一些行,并添加了一些可能有助于更好理解的代码。