我有一个 StateArray.plist 设置了 50 个字典条目,每个字典条目都包含一个带有状态名称和数字 0 的字符串。我想要做的是通过分段控件将 0 更改为 1 并保存更新的列表。我的代码在下面,不会保存更改后的号码。
-(void) viewWillAppear: (BOOL) animated
{
[super viewWillAppear:animated];
nameOfStateTextField.text = [states objectForKey:NAME_KEY];
}
//segmented control
-(IBAction)visitedChanged
{
selectedVisited = visitedSegmentedControl.selectedSegmentIndex;
}
-(IBAction)saveButton
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"StateArray.plist"];
[states setValue:selectedVisited forKey:THERE_KEY];
[states writeToFile:path atomically:YES];
}
更改后的分段控制值应以新的 THERE_KEY 结束,并写入 Documents 目录并保存。这里有什么问题?