objective c - How can I pass a parameter when initializing a UIViewController? -
i have 2 controllers, first- , secondviewcontroller. want share methods of firstviewcontroller use them in secondviewcontroller.
this how create secondviewcontroller in firstviewcontroller:
sms = [[secondviewcontroller alloc] init]; uinavigationcontroller *navcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:sms]; [self presentmodalviewcontroller:navcontroller animated:yes]; i thought of passing current instance of firstviewcontroller secondviewcontroller extends uiviewcontroller. default initwithnibname method of secondviewcontroller called.
how achieve in objective-c?
im not sure understand problem... part of issue has how instantiating secondviewcontroller... posting code help.
but answer question have asked it.... "how pass firstviewcontroller secondviewcontroller"...
in secondviewcontroller.h create own init method
-(id) initwithfirstviewcontroller:(uiviewcontroller *)thefirstviewcontroller; and in .m file...
-(id) initwithfirstviewcontroller:(uiviewcontroller *)thefirstviewcontroller { self = [super initwithnibname:@"mynibname" bundle:nil]; self.firstviewcontroller = thefirstviewcontroller; //this assumes have created property. also, not retain first view controller or circular reference , secondviewcontroller leak. return self; } then.. , here key.. make sure calling correct init method instantiate secondviewcontoller
secondviewcontroller *svc = [[secondviewcontroller alloc]initwithfirstviewcontroller:self]; now.. having said that.. looking @ rating, have feeling knew this.. , real question may be... why initwithnibname being called when not calling explicitly?
Comments
Post a Comment