0

我目前正在 iOS 中设置我的第一个应用程序的“设置/首选项”端。我目前有 NSUserdefaults 设置,以便应用记住用户的偏好。我有两个问题:

首先,一旦选择了特定单元格,它就会被选中并保存为默认值(有效),但是当我回到主设置表格视图时,我在与它链接的单元格上有一个标签,需要更新但没有t 直到我回到主页,然后再次加载设置。刷新设置视图的方法?主页(viewcontroller)也有一个我需要更新的标签,它也不需要。

其次,当要说“带有“kph”或“mph”的“测量表视图”时。我怎样才能使单元格被选中以指示其当前选择的默认值?表视图首选项之一的当前代码如下:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
// Uncheck the previous checked row
if(self.checkedIndexPath)
{
 UITableViewCell* uncheckCell = [tableView cellForRowAtIndexPath:self.checkedIndexPath];
 uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.checkedIndexPath = indexPath;

NSLog(@"cell.textLabel.text = %@",cell.textLabel.text);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:cell.textLabel.text forKey:@"windSpeed"];
[defaults synchronize];
}
4

1 回答 1

0

我想你需要在 viewWillAppear 中重新加载你的表

于 2013-10-16T00:03:38.500 回答