I am making an iOS app that uses payment methods.
At the moment I am trying to work on the checkout flow, which contains an OderFormViewController and a CheckoutTableViewController as you can see below:
I connected both by dragging a segue, as highlighted in blue. I also added a segue identifier for my segue.
I called the first view controller as E_OrderFormViewController
(Its title is Shipping Address), and in it I created an IBAction
for my Continue button and also used -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
to pass in the information.
I also have an Order model, with some properties in it. On my CheckoutTableViewController, I have got my labels and orderInfo as public properties, so the first view controller one 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 - My 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 and pass it to next view
checkoutView.orderInfo.shippingName = self.txtFieldNameOnCard.text;
NSLog(@"Shipping Name Stored: %@",checkoutView.orderInfo.shippingName);
}
}
My NSLog
always returns (null) for whatever text I type inside my first textField, which is the one I am testing first.
Here is my CheckoutTableViewController
, with its public property. The orderInfo
is listed here. I am using it to pass in the information, as I mentioned above:
//F_CheckoutTableViewController.h
#import <UIKit/UIKit.h>
@interface F_CheckoutTableViewController : UITableViewController
@property (strong, nonatomic)Order *orderInfo;
@end
On my viewDidLoad
, on my destination view controller, I did:
//F_CheckoutTableViewController.m
@implementation F_CheckoutTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
//Load all information
self.labelShippingName.text = self.orderInfo.shippingName;
NSLog(@"Typed Name: %@",self.orderInfo.shippingName);
}
I just pasted the viewDidLoad
as a reference, as I am aware if my NSLog
in my prepareForSegue
is not returning anything, the information is not being passed.
I really don't know where the error is. I searched in a couple of threads here on StackOverFlow, and none of them helped me, one which seems to be similar, is this one, but it didn't help with my issue:
Multiple segues not passing Object data between themselves
This seems to be pretty simple, but I am making some mistake that I can not find.
I really appreciate your help.
orderInfo must be null, because you didn't initialize it, therfore you cannot set its properties... so you got 2 options:
checkoutView.orderInfo = [[OrderInfo alloc]init];
checkoutView.orderInfo.shippingName = self.txtFieldNameOnCard.text;
or change your property from:
@property (strong, nonatomic)Order *orderInfo;
to:
@property (strong, nonatomic)NSString *shippingName ;
根据设置的情节提要,您在“收货地址视图控制器”中使用了“文本字段”,它可能会错过“文本字段”对其控制器的委派。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.