When I switch back and forth between views, my viewDidLoad is not being called a second time?
So I have two views. One views loads when I start the app. Then when I press开发者_C百科 a button on that view it loads a 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 triggers a method in the delegate implementation called playGame, which looks like this:
- (void)playGame {
[levelView.view removeFromSuperview];
[self.window addSubview:[gameView view]];
[UIView commitAnimations];
}
This loads the new view just fine. Then I have another button that does the same exact thing, but it brings me back to the first view. And it too, works great. I am able to navigate from one view to the other very easily. But the only problem I have, is when I try load the second view a second time, the viewDidLoad is not called again. I tested this by having an NSLog() in the viewDidLoad method.
For my app to do what I want I need the viewDidLoad to be called again. I'm guessing maybe my view isn't fully unloaded when I switch between them.
Any help is greatly appreciated.
I think you need the function viewDidAppear. viewDidLoad only gets called once per view unless something causes it to unload, such as a memory warning. viewDidAppear gets called every time that view becomes visible.
You want -viewDidAppear: for "every time the view is shown" stuff.
精彩评论