从plist获取更新数据

时间:2013-03-15 20:31:28

标签: ios objective-c cocoa-touch dictionary plist

我的app-settings plist中有一个plist。

我有2个观点。

使用呼叫按钮的第一个视图 - 我从appdelegate字典中获取电话号码。 第二个视图我设置了电话号码。 当我更改电话号码时没有任何改变。我需要重新加载应用程序才能获得更改。

这是我的代码: 的appdelegate:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
self.settingsDic = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

的firstView:

self.app=(AppDelegate*) [UIApplication sharedApplication].delegate;
[self.app getDataFromPlist];
emergencyPhone=[self.app.settingsDic objectForKey:@"emergencyPhone"];
if (emergencyPhone.length==0) {
[btnEmergency setEnabled:NO];
btnEmergency.titleLabel.numberOfLines=3;
[btnEmergency setTitle:@" Not set " forState:UIControlStateNormal];
}

settingsView:

- (IBAction)btnSaveSettings:(id)sender {
[self.app.settingsDic setValue:[NSString stringWithFormat:@"%@",etEmergencyPhone.text] forKey:@"emergencyPhone" ];
etEmergencyPhone.borderStyle=UITextBorderStyleNone;
[etEmergencyPhone setEnabled:NO];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
[self.app.settingsDic writeToFile:path atomically:YES];
[self.app getDataFromPlist];

}

1 个答案:

答案 0 :(得分:0)

self.app=(AppDelegate*) [UIApplication sharedApplication].delegate;
[self.app getDataFromPlist];
emergencyPhone=[self.app.settingsDic objectForKey:@"emergencyPhone"];
if (emergencyPhone.length==0) {
[btnEmergency setEnabled:NO];
 }
else{
[btnEmergency setEnabled:YES];
}