2013-03-15 72 views
0

我的应用程序设置plist中有一个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]; 

} 
+0

我有一个按钮,以拨打电话的用户定义。当手机没有设置按钮不起作用。 问题,在设置如果我删除一个电话号码,然后按钮停止工作 - 因为它应该。但是在我编写电话号码后,按钮不能恢复工作。 我必须关闭并重新启动软件然后我独立更改 – allpnay 2013-03-15 20:42:21

+0

我需要使用数据 – allpnay 2013-03-15 20:49:06

回答

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]; 
}