Я создал plist
файл для изменения background-color
от WallpaperViewController
до CalculatorViewController
изменением value
в plist
файл с. Мой код отлично работает в iOS симулятор, но на устройстве он не работает. Вот мой код:Изменение значения в файле Plist
WallpaperViewController
- (IBAction)changeBack:(UIButton *)sender {
NSString *buttonname = sender.currentTitle;
NSString *hello = [NSString stringWithFormat:NSLocalizedString(@"The calculator background is %@",nil) ,buttonname];
NSString *path = [[NSBundle mainBundle] pathForResource:@"CB" ofType:@"plist"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
if ([buttonname isEqualToString:@"iPhone6Calwall"]) {
[dict setObject:buttonname forKey:@"Calculatorbackground"];
[dict writeToFile:path atomically:YES];
} else if ([buttonname isEqualToString:@"Green"]) {
[dict setObject:buttonname forKey:@"Calculatorbackground"];
[dict writeToFile:path atomically:YES];
} else if ([buttonname isEqualToString:NSLocalizedString(@"Yellow",nil)]) {
[dict setObject:buttonname forKey:@"Calculatorbackground"];
[dict writeToFile:path atomically:YES];
} else if ([buttonname isEqualToString:@"Brown"]) {
[dict setObject:buttonname forKey:@"Calculatorbackground"];
[dict writeToFile:path atomically:YES];
} else if ([buttonname isEqualToString:@"Purple"]) {
[dict setObject:buttonname forKey:@"Calculatorbackground"];
[dict writeToFile:path atomically:YES];
} else if ([buttonname isEqualToString:@"Red"]) {
[dict setObject:buttonname forKey:@"Calculatorbackground"];
[dict writeToFile:path atomically:YES];
CalculatorViewController
// Read plist from bundle and get Root Dictionary out of it
NSString *path = [[NSBundle mainBundle] pathForResource:@"CB" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSString *check = [dict objectForKey:@"Calculatorbackground"];
if ([check isEqual:@"iPhone6Calwall"]) {
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"iPhone6Calwall"]]];
} else if ([check isEqualToString:@"Red"]) {
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"BMIbackground"]]];
} else if ([check isEqualToString:@"Green"]) {
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Tipbackground"]]];
} else if ([check isEqualToString:@"Yellow"]) {
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"CalYellow"]]];
} else if ([check isEqualToString:@"Brown"]) {
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"CalBrown"]]];
} else if ([check isEqualToString:@"Purple"]) {
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"CalPurple"]]];
}
Пожалуйста, не радикально изменяйте свой вопрос. Как только вы получили ответ, который решает вашу проблему, отметьте его как принятый, а затем задайте * новый * вопрос. – meagar