In iphone Application I need to pass some values to a new viewcontroller object while it create from a method in another viewcontroller class so I can initialize that values in (id)initWithNibName:method of new viewcontroller then I can load those values in viewdidLoad method.
what I want to know is how do I pass the values(parameters) to the constructor(initWithNibName) of a new viewcontrollor Object like constructor overloading in java give me some code example just showing how initWithNibName called with extra parameters and how to retrieve them in the newly created object Thanks...
Answer
this is the way I solve the problem "Observation is a object with attributes" in ViewControllor.h I put
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil set:(Observation *)observation;
in ViewControllor.m file I put
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil set:(Observation *)observation{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization on passed parameter observation object
draftObservation = observation;
}
return self;
}
then I call it this way in another class
ObsevationListView *obsevationListView = [[ObservationViewControllor alloc]
initWithNibName:@"ObservationViewControllor"
bundle:nil set:observer];
[self.navigationController pushViewController:obsevationListView animated:YES];
it works fine. I'm glad if anyone get help from this
You should create another initializer in your class, something like
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andParam:(id)aParam {
...
self.param = aParam;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With