Introducing iOS 5 segue

When implementing segue between two view controllers, how do I change the 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, but was not unsuccessful

+6
source share
4 answers

I don’t know if you still need an answer, but it was such a lonely post, and if I'm right, it no longer falls under the NDA. If I'm wrong, calm my response to oblivion, so here we go: I just finished doing what uses what you need. This is the 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 accessories for the destination view controller. Hope this helps!

+13
source

I wrote a tutorial that provides code examples for transferring information to a new scene and information from the scene using delegation, so check it out to solve your problem. iOS 5 Storyboard: How to Use Segues, Scenes, and Static Content UITableViews

+5
source

I made a video on this topic. I hope this helps. http://full.sc/17yKkZF

0
source

What I use in the source view controller:

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { UIViewController *upcomingViewController = [segue destinationViewController]; upcomingViewController.view.tag = [[segue identifier] hash]; } 

And then in the destination view controller I use (use e.g. in viewDidAppear)

 if(self.view.tag == [@"MySeqgueIdentifier" hash]) { // Do something here... } 

This is cool, since you do not need to create any properties, etc., and everything works directly from the interface constructor.

0
source

Source: https://habr.com/ru/post/898270/


All Articles