Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 segue implementation

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

like image 576
Narayanan Avatar asked Sep 29 '11 09:09

Narayanan


2 Answers

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!

like image 88
DarqueSandu Avatar answered Nov 17 '22 03:11

DarqueSandu


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

like image 31
Scott Sherwood Avatar answered Nov 17 '22 04:11

Scott Sherwood