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

前端 未结 6 401
臣服心动
臣服心动 2020-12-05 03:09

I have created a simple unwind segue using the storyboard tools. I have created the following event handler in the view I want to unwind to:

-(IBAction)quitQ         


        
6条回答
  •  借酒劲吻你
    2020-12-05 03:28

    Passing data between view controllers is frequently accomplished using protocols. Here's an example:

    In your quiz view controller header, declare a similar protocol definition:

    @protocol JBQuizViewControllerDelegate 
    
    @required
    - (void)quizController:(id)controller didQuitWithState:(NSString *)state;
    
    @end
    

    In your presenting view controller's prepareForSeque: method, wire up the delegate:

    JBQuizViewController *destination = (JBQuizViewController *)segue.destinationViewController;
    destination.delegate = self;
    

    Then, in your presenting view controller, handle the delegate protocol's quizController:didQuitWithState: method.

    Finally, once the user quits your quiz, you should notify the delegate using the protocol, passing in the state or whatever data you want to expose.

提交回复
热议问题