我的应用设置 plist 中有一个 plist。
我有 2 个视图。
使用呼叫按钮的第一个视图-我从 appdelegate 字典中获取电话号码。第二个视图我设置了电话号码。当我更改电话号码时,没有任何变化。我需要重新加载应用程序以获取更改。
这是我的代码:Appdelegate:
NSString *path = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
self.settingsDic = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
第一视图:
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];
}
设置视图:
- (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];
}