Ho to refresh view and tableview, and checkmark a default setting cell on load?

ε祈祈猫儿з 提交于 2019-12-12 02:48:52

问题


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.

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

回答1:


i guess you need to reload your table in viewWillAppear



来源:https://stackoverflow.com/questions/19353982/ho-to-refresh-view-and-tableview-and-checkmark-a-default-setting-cell-on-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!