I’m running all my apps to make sure it’s not just one app, and in every app I have, when I run on the iOS5 simulator or device, the viewWillAppear method gets called twice on every view. I have a simple NSLog(@"1");, and this appears twice in my console every time. Is this just me, or is something going on? (It only gets called once in iOS4)
This is the code calling the view that calls viewWillAppear twice:
CloseDoorViewController *closeVC;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
closeVC = [[ CloseDoorViewController alloc] initWithNibName:@"CloseDoorViewIpad" bundle:nil];
} else {
closeVC = [[ CloseDoorViewController alloc] initWithNibName:@"CloseDoorViewController" bundle:nil];
}
[self.view addSubview:closeVC.view];
[self presentModalViewController:closeVC animated:NO];
Because you are displaying the view twice.
First time by adding the view as a subview of the current view:
Second time by pushing the view’s controller on top of current view’s controller:
I’m not sure why in iOS4 the
viewWillAppearwas only called once, because iOS5 is correct to call it twice, given that you are displaying the view twice as explained above.Just remove one of the lines and it would be fine (I’d recommend removing the
addSubviewand retain thepresentModalViewControllerone).