NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:countries forKey:@"country"];
[defaults synchronize];
保存。
但我想我必须从appsettings加载数组。如何?
现在有了这个:
countries = [[NSArray alloc] initWithObjects:@"All",@"Austria",@"Belarus",@"Canada",@"Czech Republic",@"Denmark",@"Germany",@"Finland",@"France",@"Latvia",@"Norway",@"Russia",@"Slovakia",@"Slovenia",@"Switzerland",@"Sweden", @"USA", nil];
答案 0 :(得分:0)
使用 NSUserDefault 的同步方法。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int newRow = [indexPath row];
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
if (newRow != oldRow)
{
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:
indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:
lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath = indexPath;
}
NSUInteger row = [indexPath row];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//Suppose you have used **myArrayUsedInTableView** Array to construct TableView
..................................................................................
............./*Do changes here in myArrayUsedInTableView as per your requirement*/
....................................................................................
//Now store your array myArrayUsedInTableView in NSUserDefault
[defaults setObject:myArrayUsedInTableView forKey:@"StoredArray"];
[defaults synchronize];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}