如何刷新视图和表视图,并在加载时选中默认设置单元格? [英] Ho to refresh view and tableview, and checkmark a default setting cell on load?

查看:55
本文介绍了如何刷新视图和表视图,并在加载时选中默认设置单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 iOS 中设置我的第一个应用程序的设置/首选项"部分.我目前有 NSUserdefaults 设置,以便应用程序记住用户的首选项.我有两个问题:

I'm currently setting up the "Settings/preferences" side of my first app in iOS. i currently have NSUserdefaults setup so that the app remembers the users preferences. I have 2 questions:

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

Firstly, once a particular cell has been selected it is checkmarked and saved as a default(works), but when i move back to the main setting tableview, i have a label on the cell that it links with that needs to update but doesn't until i move back further to main page, then load settings again. a way to refresh the setting view? Main page(viewcontroller) also has a label that i need to update which doesn't either.

其次,当进入带有kph"或mph"的测量表视图"时.如何使单元格选中以指示其当前选择的默认值?表视图首选项之一的当前代码如下:

Secondly, when going into say the "measurement tableview with "kph" or "mph". How can i make the cell checkmarked indicating its the current selection from defaults? The current code for one of the tableview preferences is bellow:

-(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];
}

推荐答案

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

i guess you need to reload your table in viewWillAppear

这篇关于如何刷新视图和表视图,并在加载时选中默认设置单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆