2011-09-16 10 views
0

したがって、didFinishLaunchingWithOptionsに次のコードがあります。アプリケーションデリゲートとviewDidLoadが2回呼び出されました

MainViewController * tabBarController = [[MainViewController alloc] init]; 
    navigationController.delegate = self; 
    //[self.window addSubview:navigationController.view]; 
    //[self.window makeKeyAndVisible]; 
    [tabBarController release]; 

    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge| 
    UIRemoteNotificationTypeAlert| 
    UIRemoteNotificationTypeSound]; 

    return YES; 

なぜ、どのようにこれを防ぐために、誰も私に伝えることができます:私は下にaddSubViewとmakeKeyVisibleコメントを解除した場合に問題がMainViewControllerののviewDidLoadが2回呼び出されていることでしょうか?私にとっては、実際にはUIViewControllerを割り振ったときにviewDidLoadを呼び出すのは間違いありません。

答えて

1

意味があります。 UIViewControllerヘッダー:

@property(nonatomic,retain) UIView *view; // The getter first invokes [self loadView] if the view hasn't been set yet. Subclasses must call super if they override the setter or getter. 

- (void)viewDidLoad; // Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set. 
関連する問題