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
繰り返しますが、最後の行が正しく更新されるため、途方に暮れています。しかし、他の誰もそうしません。
ありがとう