objective c - How to Pass a Object to NextViewController in iOS? -
i parsing restkit values.i having entity called ey_connections
attributes.just parsing values using rkmappingoperation
in viewcontroller.m
, stored values of mappingoperation object of ey_connections
.
viewcontroller.m
@interface newconnectionviewcontroller() { dataaccesshandler *dataaccess; rkmappingresult *savedmappingresult; ey_connections *connect; } -(void)requestconnectiondata { nsstring *requestpath = @"user_history/consumer/data.json"; [[rkobjectmanager sharedmanager] getobjectsatpath:requestpath parameters:nil success: ^(rkobjectrequestoperation *operation, rkmappingresult *mappingresult) { nslog(@"result arrray us: %@",mappingresult); savedmappingresult = mappingresult; connect = ((ey_connections *)savedmappingresult.firstobject); } failure: ^(rkobjectrequestoperation *operation, nserror *error) { rklogerror(@"load failed error: %@", error); } ]; }
if click save
button means,it should pass attribute values of connect object homeviewcontroller.how pass these values.this button action
-(ibaction)save:(id)sender { //please update code pass connect object homeviewcontroller. }
link view controllers in storyboard segue , give segue name. then:
-(ibaction)save:(id)sender { [self perfromseguewithidentifier:@"mysegue" sender:self]; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { // make sure segue name in storyboard same line if ([[segue identifier] isequaltostring:@"mysegue"]) { // reference destination view controller yourviewcontroller *vc = [segue destinationviewcontroller]; // pass objects view controller here, like... [vc setmyobjecthere:object]; // or maybe vc.savedmappingresult = savedmappingresult; } }
maybe view controller somewhere else - different storyboard:
-(ibaction)save:(id)sender { uistoryboard * story = [uistoryboard storyboardwithname:@"whereisit" bundle:nil]; yourviewcontroller *vc = [story instantiateinitialviewcontroller]; // add values use instantiateviewcontrollerwithidentifier }
since bit unclear view controller coming after or should save values , return previous controller here implementation delegate:
create delegate in newviewcontroller.h
@protocol newviewcontrollerdelegate -(void) savemydata:(ey_connections*)connections; @end
when calling newviewcontroller set delegate homeviewcontroller so:
newviewcontroller *nvc = // instantiate somehow nvc.delegate = self;
then in homeviewcontroller implement method saving:
-(void) savemydata:(ey_connections*)connections{ // save data here variabels in home view controller }
and then, in method call:
-(ibaction)save:(id)sender { [delegate savemydata:connect]; }
to have covered, can use unwind segue , reuse prepare segue had down there.
if using present view controller can:
a) use delegate shown above
b) cast presentingviewcontroller
homeviewcontroller
, assign there.
here explanation delegates:
Comments
Post a Comment