Getting the value of the switch switch from the settings

I need to load different background images into the first ViewController UIImageView, called the background, depending on what settings are used to switch the toolbar in the Settings Panel.

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 have no warnings, but I cannot set the image that will be used.

Any ideas for a solution?

+4
source share
2 answers

Make sure your IBOutlet is connected correctly and use [background setImage:] instead of dot notation. If none of them work, you have a problem with your logic or setting / reading the value of userDefault.

+1
source

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

+2
source

Source: https://habr.com/ru/post/1445777/


All Articles