views:

152

answers:

1

Hi guys,

I have a custom UIViewController subclass, which gets pushed on a UINavigationController stack. I want to add some data of my own at the time of initialization/pushing. Should I

a) write a custom init method with my data as argument, like this?

MyCustomViewControllerSubclass.m:

-(id) initWithNibName: bundle: myCustomData: {
    if(self = [super initWithNibName: bundle:]){
    //do stuff with my data
    }
    return self;
}

or b) add a property to my viewcontroller that stores my custom data and then add it after initialization?

Is there some advantage/disadvantage in one of these approaches or is there another way to do this?

Very happy for replies!

+1  A: 

Absolutely, I do this all the time. Even better, forget about the nib name stuff completely and do:

- (id) initWithMyCustomData: (id) customData
{
    if(self = [super initWithNibName: @"MyNibName" bundle: nil]){
        //do stuff with my data
    }
    return self;
}
St3fan
This is also what I do.
Prairiedogg
Ok, great, I'll do it like this. Thanks!
megamer