Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top