Iphone 将选中标记的行保存到appsettings中。编辑
编辑:我得到了一个保存,现在它不工作Iphone 将选中标记的行保存到appsettings中。编辑,iphone,cocoa-touch,uitableview,Iphone,Cocoa Touch,Uitableview,编辑:我得到了一个保存,现在它不工作 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:countries forKey:@"country"]; [defaults synchronize]; 储蓄 但是我想我必须从appsettings加载数组。怎么做 现在我明白了: countries = [[NSArray alloc] initWithObjects:@"Al
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];
使用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];
}