Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard Modal Segue with delegate

I've made an app using iOS6 unwind segues not realising they weren't in iOS5 and so i'm taking it apart in order to support iOS5. So far i've worked out that I need to use delegates in order to get information back to my root view from the modal segue view and have a couple of good examples to follow and i'm quietly confident I get it.

Currently the modal segue is generated via the storyboard however, not via code.

In order to set it's delegate as my root view will I need to generate it via code instead or is there a way via the storyboards?

like image 464
Matt Stuttard Parker Avatar asked Dec 20 '22 13:12

Matt Stuttard Parker


1 Answers

Before performing the segue the program will call the method - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender in the sourceViewController (the view controller that calls the segue). In this method you can give the destinationViewController a reference to self:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    [segue.destinationViewController setDelegate:self];
}

Of course you need the property in the destinationViewController:

@property (weak, nonatomic) id<yourProtocol> delegate;

Hope it helps.

like image 83
pedros Avatar answered Dec 30 '22 13:12

pedros