IPhone initializes UIViewController with additional data

I have a custom subclass of UIViewController that pops into the UINavigationController stack. I want to add some of my data during initialization / click. Should I

a) write your own init method with my data as an argument, how is it?

MyCustomViewControllerSubclass.m:

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

or b) add a property to my view manager, which stores my user data, and then add it after initialization?

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

Very happy for the answers!

+3
source share
1 answer

, . , :

- (id) initWithMyCustomData: (id) customData
{
    if(self = [super initWithNibName: @"MyNibName" bundle: nil]){
        //do stuff with my data
    }
    return self;
}
+6

Source: https://habr.com/ru/post/1735330/


All Articles