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

前端 未结 6 396
臣服心动
臣服心动 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:19

    Set up a delegate and inform your source view controller about quitting the quiz and send back the data. Don't forget to set the source view controller as the delegate of the destination view controller.

    // DestinationViewController.h
    @protocol DestingationDelegate;
    @interface 
    ...
    @property (assign) id delegate;
    ...
    @end
    
    @protocol DestinationDelegate
    -(void)didQuitQuiz:(NSDictionary*)infoDict;
    @end
    
    // DestinationViewController.m
    -(IBAction)quitQuiz:(UIStoryboardSegue *)segue {
      NSLog(@"SEGUE unwind");
      if (self.delegate) [self.delegate didQuitQuiz:infoDict];
    }
    
    
    // SourceViewController.h
    #import DestinationViewController.h
    @interface SourceViewController : ViewController 
    ....
    
    // SourceViewController.m
    -(void)didQuitQuiz:(NSDictionary *)infoDict {
        if (infoDict) {
           // do something with the data
        }
    }
    
    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
       ...
       destinationViewController.delegate = self;
    }
    

提交回复
热议问题