简体   繁体   中英

Knowing from the main view controller when the presented modal view controller is dismissed?

I wanted to know if its possible to know from the view controller when its presented modal view controller is dismissed ? (ie when its view returns?)

I tried:

viewWillAppear
viewDidAppear

But, these didnt seem to work :(

Can anyone kindly suggest ? Thanks.

Here's a callback solution which takes less modifications to your modal and parent:

In the Model's .h add:

@property (nonatomic, copy) void (^dismissed)();

In the Model's .m put this in the completion when you dismiss the modal:

[self dismissViewControllerAnimated:YES completion:^{
    if(self.dismissed)
        self.dismissed();
}];

In the parent view controller when you instantiate your modal set the dismissed callback:

Modal = //Init your modal
[Modal setDismissed:^{
    //do stuff you wanted when it's dismissed
}];
[self presentViewController:Modal animated:YES completion:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM