As I move more and more of my UI construction from XCode to IB there is one remaining hurdle I need to clear.
Currently, I create my custom viewControllers in XCode with custom initializers. They typically have a bunch of ivars that are set during initialization via passed params. I would really like to move as much of this as I can to IB.
Could someone carefully explain to me – or, better, point me to code – how to replicate the XCode approach of passing params via custom initializer in IB – presumably via IBOutlet.
Thanks in advance.
Cheers,
Doug
UPDATE:
A typical scenerio is my AppDelegate will go out to the network, grab some data – NSMutableData, and then pass a reference to a root viewController – typically a TableViewController – that is pushed on the viewController stack of an navigationController.
When a cell is selected an secondViewController is alloc/init’ed and a subset of the data is passed to it. The secondViewController goes to the network for a bit more data, builds a view hierarchy, hands bits of the retrieved data to each subview and then each subview is messaged with setNeedsDisplay to process the data.
It is this hierarchical data passing that I want to hand off to IB is possible.
You can still have a custom initializer. However, inside this initialized you’ll call
-[initWithNibName:@"yourNibName" bundle:bundle]. You will connect yourUIKitrelated instance variables (UILabel,UIButton, etc.) in Interface builder and therefore won’t have to instantiate those objects in your initializer. Other instance variables (strings, dictionaries, custom objects, etc.) you’ll instantiate and set in your initializer.Also, keep in mind that manipulation of your
UIKitrelated variables such as setting label text, or setting the position of aUIView, should be done in theviewDidLoadmethod since these objects may not have been fully created at the time initializer is executing.Let me know if you need more information.