iOS 6 - can i return data when i unwind a segue? iOS 6 - can i return data when i unwind a segue? xcode xcode

iOS 6 - can i return data when i unwind a segue?


Thanks Jeff. After watching WWDC video 407 I have a clear solution.

In the view controller that is the target of the unwind you should create a method that takes a single UIStoryboardSegue parameter and returns an IBAction. The UIStoryboardSegue has a method to return the source view controller! Here is the example taken from the video (credit to Apple).

- (IBAction)done:(UIStoryboardSegue *)segue {    ConfirmationViewController *cc = [segue sourceViewController];    [self setAccountInfo:[cc accountInfo]];    [self setShowingSuccessView:YES];}


Getting data back from an unwind segue is explained very nicely in this apple talk, second half of the presentation (edit: starts from 37:20)

In particular, in an unwind segue the [segue sourceViewController] is the still active view controller from which the unwind event originated, so just access your properties as usual.


Add the function prepareForSeque in the controller being closed.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

This function is called before the unwind segue is called (in your example you called it quitQuiz). As you can see, it also has a sender parameter so that you can find out who called the unwind and collect the relevant data accordingly.

For example of the WWDC 407 video, if you clicked the reset button you would not set the accountInfo and if you clicked the done button you would.