简体   繁体   中英

Xcode 4 - viewDidLoad issue

Is anyone else having issues with Xcode 4 where viewDidLoad is being called twice? I have run the same project in both Xcode 3.2 and Xcode 4 and it only acts up in Xcode 4.

After researching this on the Apple Developer forums , it seems that in some cases Xcode 4 creates bugged Interface Builder NIBs. The effect is that the application's rootViewController gets loaded in twice, which really screws things up. The same project loaded in Xcode 3 won't exhibit the problem.

In my universal app, it only affected the iPad NIB. The iPhone was fine.

I was able to solve this issue by:

  • Removing the rootViewController connection in Interface Builder (this causes the app to load with window.rootViewController = nil )
  • In viewDidLoad for the main controller (the one that was being loaded twice), I then manually assign appDelegate.window.rootViewController = self

So far this seems to have the desired effect.

I had same issue. And i resolved it. It happens when your app memory did get memory warning.

Put a breakpoint to memoryDidReceiveWarning. It get's called, and clear your class object memory. So your viewDidLoad Get called twice, because it has no memory at that time.

Xcode is just the IDE -- it shouldn't have any bearing on what happens when your app is executing. If there's a difference, it seems more likely that you're building for different iOS versions.

Did you set the view of the view controller? I had the same issue and I realized that I didn't set the view property.

- (void)viewDidLoad {
    UIView *contentView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame];
    //add some stuff to contentView here
    self.view = contentView;
    [contentView release];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM