AppDelegate からのアイテムのリストを含むテーブル ビューがあります。テーブル ビューでは、ユーザーが必要な項目を選択できます。選択が完了すると、項目の横にチェックマークが表示されます。次に、ユーザーは前の画面に戻ることができます。この選択により、ユーザーに表示される文字列値が更新されます。この値は AppDelegate にも格納されます。すべてがうまく機能しますが、ユーザーが選択を変更できる画面に戻ることを選択した場合、この値が自動的に選択されるようにしたいと思います。
これが私の SetSizeViewController.m の cellFroRowAtIndexPath 関数です。
appDelegate.selectedSize に格納されている値を選択するのに問題があります。たとえば、この値は「メーター」のようなものです。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.checkedIndexPath = indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *result = nil;
static NSString *CellIdentifier = @"CellIdentifier";
result = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (result == nil){
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
TabAndSplitAppAppDelegate *appDelegate = (TabAndSplitAppAppDelegate *)[[UIApplication sharedApplication] delegate];
SetSize *setSize = (SetSize *)[appDelegate.setSizes objectAtIndex:indexPath.row];
appDelegate.selectedSize = setSize.name;
appDelegate.selectedSizeCheckedIndexValue = (NSInteger *)indexPath.row;
[tableView reloadData];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
TabAndSplitAppAppDelegate *appDelegate = (TabAndSplitAppAppDelegate *)[[UIApplication sharedApplication] delegate];
if(appDelegate.selectedSize.length > 0)
{
if ((int)indexPath.row == (int)appDelegate.selectedSizeCheckedIndexValue) {
[cell setSelected:YES animated:YES];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
[cell setSelected:NO];
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
}