While implementing a segue between two view controllers how to change a property of the destination view controller using the segue object? The documentation says that this can be done inside the prepareForSegue: sender: method. i tried it but not was not successful
I don't know if you still need an answer to this, but it was such a lonely post, and if I'm correct, this doesn't fall under NDA any longer. If I'm mistaken, please moderate my answer into oblivion, so here we go: I just finished doing something that uses what you need. This is code that works for me:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"relevantSegueIdentifier"])
{
// [segue destinationViewController] is read-only, so in order to
// write to that view controller you'll have to locally instantiate
// it here:
ViewController *upcomingViewController = [segue destinationViewController];
// You now have a solid reference to the upcoming / destination view
// controller. Example use: Allocate and initialize some property of
// the destination view controller before you reach it and inject a
// reference to the current view controller into the upcoming one:
upcomingViewController.someProperty = [[SomePropertyClass alloc] initWithString:@"Whatever!"];
upcomingViewController.initialViewController = [segue sourceViewController];
// Or, equivalent, but more straightforward:
//upcomingViewController.initialViewController = self;
}
}
This assumes that both someProperty and initialViewController are synthesized accessors of the destination view controller. Hope this helps!
I have written a tutorial that gives code examples for passing information to the new scene and information back from a scene using delegation so check it out it should solve your problem. iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews
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