Xcode 4 - problem with viewDidLoad

Does anyone else have problems with Xcode 4 where viewDidLoad is called twice? I run the same project in both Xcode 3.2 and Xcode 4, and it only works in Xcode 4.

+6
ios iphone xcode ipad
source share
4 answers

After exploring this on the Apple Developer Forums , it seems that in some cases, Xcode 4 creates NIB plug-ins with an Interface Builder interface. The effect is that the rootViewController application loads twice, which really pushes it. The same project loaded in Xcode 3 will not detect a problem.

In my universal application, this only affected the iPad NIB. The iPhone was fine.

I was able to solve this problem:

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

So far, this seems to have the desired effect.

+4
source share

Xcode is just an IDE - it should not have anything to do with what happens when your application runs. If there is a difference, it seems more likely that you are creating different versions of iOS.

0
source share

Have you set the view controller view? I had the same problem and realized that I did not 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]; } 
0
source share

I had the same problem. And I decided that. This happens when the memory of your application receives a memory warning.

Place a breakpoint in memoryDidReceiveWarning. It is called and clears the memory of the class object. Thus, your viewDidLoad Get is called twice because at that time it has no memory.

0
source share

All Articles