Sunday, April 17, 2011

iPhone - Multiple nib application IBOutlet is nil

Hi, I have a multiple nib application, and on my awakeFromNib: method, some IBOutlets are in nil. I think I have narrowed down the problem, but I'm not sure why. I have a MainWindow.xib file, that was created by XCode. In there, I have the application delegate, and several ViewControllers (one per each other nib I have). One of them, let's call one of them the MatrixViewController. I also have a MatrixView.xib file, where I have the controller and the view. What I want to do is from MatrixViewController's awakeFromNib initialialize something from its view. However, all the outlets in it are nil.

I think this is because the awakeFromNib: I'm responding to was sent when loading MainWindow.xib and not MatrixView.xib, am I correct?

What is the alternative to solve this? One good thing about it, is that all the initialization is done when the application loads, which I'd like to keep.

Thank you!

From stackoverflow
  • Use -viewDidLoad instead of -awakeFromNib

    It's one of those iPhone vs MacOSX differences.

  • The IBOutlets should only be referenced from viewDidLoad if you want to change them before the view is displayed.

    The nib may not have been loaded when awakeFromNib is called.

0 comments:

Post a Comment