Search code examples
propertiesios5storyboardpushviewcontroller

iOS 5 MainStoryBoard : When linking a view as PUSH, can we set a property?


I know we still can do it by programmation,.. that's what i'm using for now (as iOS 4). The old way was to init your controller, set property, then Push.

But with iOS 5, since the main storyboard is the "new" way to design your application. I was wondering if it is any possible way to do the same, setting a property then pushing using the link in your mainstoryboard ? It is so easy now to push, but not really useful if you want to set a property....

I don't know if I explained it clearly.. but it is really basic stuff.

Anyone?


Solution

  • You'd now use prepareForSegue: method to do any customisation. You can grab a reference to the view you're about to push and manipulate it, similar to this...

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        // Check we're referring to the right segue
        if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
        {
    
            // Get reference to the destination view controller
            YourViewController *vc = [segue destinationViewController];
    
            // Do your customisations here
        }
    
    }
    

    I just wrote two blog posts on how to do this. You can read it here and it should clarify (with example) how to do it.