Update a scrollview image based on a UISwitch on a modal view
Let me explain. I have a开发者_开发问答n iPhone app, nearly, that displays an image in a scrollView controlled by the MainViewController. I open an OptionsView that shows a UISwitch that is linked to the settings bundle. The link to the settings is all good. When the user clicks the UISwitch on the OptionsView and clicks the Done button, I want to close the modal view and for the image to be replaced with the alternative image. An On image, or an Off image.
The NSUserDefaults are all correct, and I have an if/else in the MainViewController under the ViewDidLoad method. This works each time the app is loaded into the simulator, but doesn't control the image when the app is running and the UISwitch is changed. It seems to me that the if/else should be in something other than ViewDidLoad or I need to get the Done button to somehow update the image. Could anyone point me in the right direction?
Did you synchronized the NSUserDefaults after changing the value of the switch? Try calling
[[NSUserDefaults standardUserDefaults] synchronize];
after you set the new value and see if that helps. Also try moving your if/else statement in the - (void)viewWillAppear:(BOOL)animated
method because - (void)viewDidLoad
is only called once when the view is loaded but not when the modal view is closed.
精彩评论