ios - Initializing a UIViewController correctly and passing in properties -


i have uiviewcontroller called testviewcontroller.h/.m:

header file has:

@property (nonatomic, assign) bool istested; 

implementation file has:

@implementation testviewcontroller  - (void)viewdidload {     if (_istested)     {         [self postnotification];         [self listentonotifications];     } } 

i have view has this:

- (void) replytappressed {     testviewcontroller *test = [[testviewcontroller alloc] init];      test.istested = no;      [_parent.navigationcontroller pushviewcontroller:test animated:yes]; } 

through app's life cycle, testviewcontroller's property starts off yes; when view gets called, should set property no; - does.

but _parent (which parent uiviewcontroller) , test both null.

am initializing , implementing wrong?

thanks.

you may try in below ways -

testviewcontroller.m

- (id)initwithtested:(bool)value {      if (self = [super init])     {         self.istested = value;     }     return self; }  - (void) replytappressed {     testviewcontroller *test = [[testviewcontroller alloc] initwithtested:no];      [_parent.navigationcontroller pushviewcontroller:test animated:yes]; } 

Comments