tags:

views:

71

answers:

2

I've implemented a View Controller, and I'm trying to do some very basic initialization in initWithNibFile...which I understand to be the designated initializer for View Controller objects.

I've tried to put breakpoints on the code, and have put very simple NSLog statements into it as well. Regardless...I'm not seeing it be executed (and the object i'm attempting to alloc/init inside the function is also not being allocated - so I'm about 99% sure I'm not hitting the code.

Is there something I need to do elsewhere to cause this method to be invoked?

I'm getting a clean build, no warnings or errors. And the app successfully loads up the View, and I can invoke a ButtonClick method I've coded and connected to this same View Controller.

Any suggestions would be appreciated.

TC

A: 

I ended up moving my allocation logic to viewDidLoad, and that works fine.

Not sure why the initWithNibFile was not working...but I'll take the small victory !!!

Thanks for offering to look at the code bpapa.

initWithNibFile is if you're create a class that is meant to be created directly. Since anything you pack into a nib file is a serialized object, initWithNibFile never actually gets called in the running application. That's why you have delegates like awakeFromNib and viewDidLoad.
Jason Coco
A: 

You probably need initWithCoder: It's what the SDK uses to read from nib files during startup.

initWithNibFile: is almost never called by the system. Usually you call this manually. The documentation is quite misleading on this point.

In any case, be careful doing too much initialization in the initWithXXXX methods. The view's targets and actions aren't likely to be set up and connected yet. viewDidLoad is almost always the right place to do viewController setup anyways.

Kailoa Kadano