Passing parameters using initWithNibName:

In an iphone application, I need to pass some values ​​to a new viewcontroller object when it is created from a method in another viewcontroller class, so I can initialize these values ​​in the (id) initWithNibName: method of the new view manager, after which I can load these values ​​into the viewdidLoad method.

I want to know how to pass values ​​(parameters) to the constructor (initWithNibName) of a new viewcontrollor object as an constructor overload in java, give me a code example showing how initWithNibName is called with additional parameters and how to restore them in a newly created object Thanks ...


Answer


so I solve the problem "Observation is an object with attributes" in ViewControllor.h I put

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil set:(Observation *)observation;

in the file ViewControllor.m 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;

}

 ObsevationListView *obsevationListView = [[ObservationViewControllor alloc]  
                                          initWithNibName:@"ObservationViewControllor" 
                                          bundle:nil set:observer];
[self.navigationController pushViewController:obsevationListView animated:YES];

. , -

+5
2

, -

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andParam:(id)aParam {
...
self.param = aParam;
}
+7

- :

initWithNibName:bundle:

0

All Articles