I need to put it some custom logic into my iPhone app so that depending on what iOS version you are running, choose a different XIB file (i.e. iPhone or iPad will show different XIB files).
I had built the whole iPhone app from day one and its all good, using a tabbarcontroller and the standard navigation controllers in each tab.
So I implemented the :
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
method, only to find that it does not get called. (I have a breakpoint and log statements in it and nothing gets hit).
Does anyone know why this might be? OR how can i achieve this functionality?
I have read somewhere that initWithNibName is only called when you call it, i.e. when you programatically construct your view hierarchy, is this true??
If you're not doing something like this before adding it to your navigation controller:
SomeViewController *someViewController = [[SomeViewController alloc] initWithNibName:...];
Then chances are good you're overriding the wrong method.
If your view controller lives in a nib file, say your navigation controller's nib file, it will be unarchived from the nib file as a new view controller object, instead of being created with its own nib file, so the above method won't be called.
You'll have to override -awakeFromNib
instead.
If your view controllers are loaded from a .xib
file then initWithCoder:
will be called instead. The initWithNibName:bundle:
method is only used for programatically creating view controllers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With