Luca Rossi
Luca Rossi

Reputation: 3

How perform an animated custom segue in storyboard w/o NavigationController?

I have the necessity to set some parameters before execute a segue, so I must use CUSTOM SEGUE, right? In this case, I would make the transition, from a screen to another, animated but I don't have a NavigationController (and I don't want to insert one!)

Is it possible to not use a NavigationController and change views with a custom segue?

In alternative, there is the possibility to set an action for a button and execute some rows of code befor performing a segue? I found this solution :

}

but it need navigtion controller...

thank you to all and sorry for my bad englis!

Upvotes: 0

Views: 2047

Answers (1)

T.J.
T.J.

Reputation: 3960

When you create you segue in Storyboard, select "modal" instead of "push" (custom refers to a third type which I don't think you need). Select the segue and use the attributes inspector to give it a name. In my code example I use the name "editTitleBlock".

To set properties on the destination view controller (which will be the modal view controller) put a prepareForSegueMethod in your first view controller like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"editTitleBlock"])  {
        [[segue destinationViewController] setTitleFieldString: @""];
        [[segue destinationViewController] setAltitudeFieldString:currentLocation.localizedAltitudeString];
        [[segue destinationViewController] setLocationFieldString:currentLocation.localizedCoordinateString];
        [[segue destinationViewController] setAuthorString:userName];

    if ([[segue identifier] isEqualToString:@"cancel"])  {
        // do nothing special
    }
}

to get back to the first view controller use:

[self dismissModalViewController animated:YES];

Upvotes: 0

Related Questions