ios - Segue not passing data between ViewControllers -
i making ios app uses payment methods.
at moment trying work on checkout flow, contains oderformviewcontroller , checkouttableviewcontroller can see below:
i connected both dragging segue, highlighted in blue. added segue identifier segue.
i called first view controller e_orderformviewcontroller
(its title shipping address), , in created ibaction
for continue button , used -(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender
pass in information.
i have order model, properties in it. on checkouttableviewcontroller, have got labels , orderinfo public properties, first view controller 1 can access it.
#import <foundation/foundation.h> @interface order : nsobject @property(strong, nonatomic) nsstring *shippingname; @property (strong, nonatomic) nsstring *shippingaddress; @property (strong, nonatomic) nsstring *shippingcity; @property(strong, nonatomic) nsstring *shippingstate; @property(strong, nonatomic) nsstring *shippingzip; @end //e_orderformviewcontroller.m #import "e_orderformviewcontroller.h" #import "f_checkouttableviewcontroller.h" ... #pragma mark - actions - (ibaction)storepaymentinfoproceedtoconfirmation:(id)sender { [self performseguewithidentifier:@"tocheckout" sender:self]; } #pragma mark - navigation -(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{ if ([[segue identifier] isequaltostring:@"tocheckout"]) { f_checkouttableviewcontroller *checkoutview = segue.destinationviewcontroller; //store information , pass next view checkoutview.orderinfo.shippingname = self.txtfieldnameoncard.text; nslog(@"shipping name stored: %@",checkoutview.orderinfo.shippingname); } }
my nslog
returns (null) whatever text type inside first textfield, 1 testing first.
here checkouttableviewcontroller
, public property. orderinfo
is listed here. using pass in information, mentioned above:
//f_checkouttableviewcontroller.h #import <uikit/uikit.h> @interface f_checkouttableviewcontroller : uitableviewcontroller @property (strong, nonatomic)order *orderinfo; @end
on viewdidload
, on destination view controller, did:
//f_checkouttableviewcontroller.m @implementation f_checkouttableviewcontroller - (void)viewdidload { [super viewdidload]; //load information self.labelshippingname.text = self.orderinfo.shippingname; nslog(@"typed name: %@",self.orderinfo.shippingname); }
i pasted viewdidload
reference, aware if nslog
in prepareforsegue
not returning anything, information not being passed.
i don't know error is. searched in couple of threads here on stackoverflow, , none of them helped me, 1 seems similar, one, didn't issue:
multiple segues not passing object data between themselves
this seems pretty simple, making mistake can not find.
i appreciate help.
orderinfo must null, because didn't initialize it, therfore cannot set properties... got 2 options:
checkoutview.orderinfo = [[orderinfo alloc]init]; checkoutview.orderinfo.shippingname = self.txtfieldnameoncard.text;
or change property from:
@property (strong, nonatomic)order *orderinfo;
to:
@property (strong, nonatomic)nsstring *shippingname ;
Comments
Post a Comment