我试图在 viewDidAppear 方法访问中调用我的表行上的 reloadData。但是,我的单元格没有刷新它们的值,我不知道为什么,因为似乎所有内容都按照预期的顺序访问。更奇怪的是,实际上 1 行确实会刷新,但其他行都不会。
这是我的代码...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Set up the cell...
static NSString *CellWithIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
NSLog(@"generating cell contents");
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [_tableGroup.options objectAtIndex:rowcount];
rowcount++;
//label for currently selected/saved setting
_currentSetting = [[UILabel alloc] initWithFrame:CGRectMake(160, 8, 115, 25)];
[_currentSetting setFont:[UIFont systemFontOfSize:14]];
_currentSetting.backgroundColor = [UIColor clearColor];
_currentSetting.textColor = [UIColor blueColor];
_currentSetting.textAlignment = NSTextAlignmentRight;
[cell.contentView addSubview:_currentSetting];
NSLog(@"added new label to cell");
}
//depending on the setting, set the label in the cell to what is currently selected
if (indexPath.section == 1 && indexPath.row == 0) {
_currentSetting.text = [NSString stringWithFormat:@"%@ %@",[settings.mapDistance stringValue], NSLocalizedString(@"MILES_IDENTIFIER", nil)];
NSLog(@"setting map distance label: %@", settings.mapDistance);
}
else if(indexPath.section == 1 && indexPath.row == 1)
{
_currentSetting.text = [NSString stringWithFormat:@"%@ %@",[settings.maxCustomers stringValue], NSLocalizedString(@"ITEMS_IDENTIFIER", nil)];
NSLog(@"setting max customers: %@", settings.maxCustomers);
}
else if(indexPath.section == 2)
{
_currentSetting.text = [NSString stringWithFormat:@"%@ %@",[settings.maxProducts stringValue], NSLocalizedString(@"ITEMS_IDENTIFIER", nil)];
NSLog(@"setting max products: %@", settings.maxProducts);
}
return cell;
}
基于这段代码,我用我的 NSLOGS 得到这个输出。
这是创建视图时单元格的第一次运行。它生成 4 个单元格,在每个单元格中放置标签,并在其中 3 个标签中放入一个值。
generating cell contents
added new label to cell
generating cell contents
added new label to cell
setting map distance: 15
generating cell contents
added new label to cell
setting max customers: 250
generating cell contents
added new label to cell
setting max products: 150
在这一点上,我点击了一行,转到另一个屏幕,现在已经返回。如您所见,地图距离是不同的。尽管没有显示任何更改,即使在重新加载过程中访问了更改标签文本的代码。
reloading data
generating cell contents
generating cell contents
setting map distance: 25
generating cell contents
setting max customers: 250
generating cell contents
setting max products: 150
再次,我不知所措,因为最后一行确实刷新了。但其他人都没有。
谢谢