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开发者_如何学JAVA.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.
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];
}
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.
精彩评论