UIView notification when modal UIImagePickerController is dismissed?

后端 未结 3 1668
天涯浪人
天涯浪人 2021-01-27 00:50

Is there a way to call code when a modal view is finished dismissing?

EDIT:

I\'m sorry, I didn\'t clarify earlier. I\'m trying to dismiss a UIImagePickerControll

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-27 01:28

    I don't think there is a specific notification yet can subscribe to, to know when dismiss animation is done,...BUT. You can implement viewDidAppear: in the view controller that presented the modal view. This is what I do, when I use the (to UIImagePickerController quite similar) ABPeoplePickerNavigationController.

    In the callback from people picker, I remember the person tapped in the picker on an instance variable, like this:

    - (void)callbackFromModalView:(id)dataFromModalView {
        // remember dataFromModalView as I need it when dismissed
        self.dataFromModalView = dataFromModalView;
    
        // now initiate dismissal
        [self dismissModalViewControllerAnimated:YES];
    }
    

    then, in your view controller, implement this:

    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        if (self.dataFromModalView) {
            //...present now view here
    
            // don't forget to reset this one
            self.dataFromModalView = nil;
        }
    }
    

    in effect, you are using the combination of viewWillAppear: and the dataFromModalView property as the "notification about modal view dismissed".

提交回复
热议问题