When I switch between views, is my viewDidLoad not called a second time?

So, I have two kinds. When I launch the application, you view the loads. Then, when I click the button on this view, it loads another view.

- (IBAction)triggerGame { leveldata = [[NSMutableDictionary alloc] init]; [leveldata setValue:@"hide" forKey:@"shootarrow"]; [leveldata writeToFile:[self levelFilePath] atomically:YES]; [leveldata release]; Papertoss_MaraAppDelegate *mainDelegate = (Papertoss_MaraAppDelegate *)[[UIApplication sharedApplication] delegate]; [mainDelegate playGame]; } 

This action calls a method in the delegate implementation called playGame, which looks like this:

 - (void)playGame { [levelView.view removeFromSuperview]; [self.window addSubview:[gameView view]]; [UIView commitAnimations]; } 

It loads a new view very simply. Then I have another button that does the same thing, but returns me to the first view. And that also works great. I can easily move from one sight to another. But the only problem I encountered is when I try to load the second view a second time, viewDidLoad is not called again. I checked this with NSLog () in the viewDidLoad method.

For my application to do what I need, I need to call viewDidLoad again. I assume that my gaze is not completely unloaded when I switch between them.

Any help is appreciated.

+6
iphone cocoa-touch uikit ipad viewdidload
source share
2 answers

I think you need the viewDidAppear function. viewDidLoad only receives a call once per view, unless something causes it to be unloaded, such as a memory warning. viewDidAppear is called every time a view becomes visible.

+9
source share

You want -viewDidAppear: for "whenever the view is displayed."

+4
source share

All Articles