【发布时间】:2013-03-04 17:00:30
【问题描述】:
我的应用设置 plist 中有一个 plist。
我有 2 个视图。
带有呼叫按钮的第一个视图 - 我从 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];
}
【问题讨论】:
-
我有一个按钮可以拨打用户定义的电话。当电话未设置按钮不起作用。问题,在设置如果我删除一个电话号码然后按钮停止工作 - 它应该。但是在我打了一个电话号码后,按钮就不会恢复工作了。我必须关闭并重新启动软件,然后我才能独立更改
标签: ios objective-c cocoa-touch dictionary plist