Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving toggle switch value from Settings bundle

I need to load different background images in first ViewController's UIImageView called background , depends on what settings is used for toggle switch in Settings Bundle.

In -viewWillAppear in ViewController.m

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id toggleSwitchValue = [defaults objectForKey:@"PSToggleSwitchSpecifier"];
BOOL boolToggle = [toggleSwitchValue boolValue];

// setting custom back for viewController
if (boolToggle == YES) {
    [self.backGround setImage:[UIImage imageNamed:@"1.png"]];
    NSLog(@"YES");
} else if (boolToggle == NO) {
    [self.backGround setImage:[UIImage imageNamed:@"2.png"]];
    NSLog(@"NO");
}

I haven't warnings but i can't set image what will be used.

Any ideas to solve?

like image 734
Alex Avatar asked Oct 23 '22 02:10

Alex


2 Answers

Make sure that, if the view is loaded from a nib, you modify the view in or after viewDidLoad.

like image 188
Brendon Avatar answered Nov 03 '22 19:11

Brendon


Make sure your IBOutlet is wired up correctly and use [background setImage:] instead of dot notation. If neither works, you have an issue with your logic or setting/reading of the userDefault value.

like image 40
HackyStack Avatar answered Nov 03 '22 20:11

HackyStack