I am using this function to switch between views in Xcode 4.3.
[self performSegueWithIdentifier:@"NextView" sender:self];
I would like to pass some parameters between pages. How can I do that?
To pass data back, the most common approach is to create a delegate property in your detail view controller, like this: class ViewControllerB: UIViewController { var selectedName: String = "Anonymous" weak var delegate: ViewControllerA! }
Control + click the UI element you are going to use to make the bridge and drag to the second View Controller. Select the “Show” option from the “Action Segue” menu. Control + click the button and drag to the second ViewController, then select “Show.”
This question has a very nice and correct explanation of passing data between view controllers:
Passing Data between View Controllers
After performSegueWithIdentifier:sender:
your view controler will call
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
assuming your new view controller has some propertys to set:
if ([[segue identifier] isEqualToString:@"NextView"]) {
MyViewController *myVC = [segue destinationViewController];
myVC.propertyToSet = // set your properties here
}
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