ViewWillAppear called twice in iOS5

I run all my applications to make sure that this is not only one application, and in every application that I have, when I launch the iOS5 simulator or device, the method viewWillAppearis called twice on each view. I have a simple NSLog(@"1");one and it appears twice in my console every time. Is it just me, or is something happening? (It only gets called once in iOS4)

This is the code that invokes the view that invokes 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];
+5
source share
4 answers

Because you show the show twice.

The first time, adding a view as a subview of the current view:

[self.view addSubview:closeVC.view];

, :

[self presentModalViewController:closeVC animated:NO];

, iOS4 viewWillAppear , iOS5 , , , .

, ( addSubview presentModalViewController ).

+10

-addSubview:.

- " ", -viewWillAppear: .. .

, -addSubview:/- removeFromSuperView view view view iOS 5, " " ( / ). "" , -presentModalViewController: ( " " ).

iOS 5 Apple -addSubview:/- removeFromSuperView, . , , viewController, " " .

, .

" UIViewController Containment" .

+16

(iOS 4) , :

- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
    return NO;
}
+5

:, , , , . /.

:

( ) -init . , .

(note that if you have not yet redefined the method -initin this class, make sure you redefined the assigned initializer, which is equal -[UIViewController initWithNibName:bundle:])

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html

+1
source

All Articles