开发者

How to get a notification when a form sheet (UIModalPresentationFormSheet) has disappeared?

开发者 https://www.devze.com 2023-03-01 04:01 出处:网络
I开发者_JS百科 have a view controller (A) that presents another view controller (B) modally as a form sheet (UIModalPresentationFormSheet).

I开发者_JS百科 have a view controller (A) that presents another view controller (B) modally as a form sheet (UIModalPresentationFormSheet).

Now I want to dismiss view controller B, and present another as soon as it's safe to do so (because you can't use presentModalViewController: while another view controller is being shown or dismissed.)

However, I can't seem to find any way to be notified when the form sheet has fully disappeared. Any solutions?


As no doubt you have noticed, the old viewDidAppear methods are not fired when the UIModalPresentationFormSheet controller is dismissed. One can emulate the viewWillAppear call by simply calling that method when you dismiss the controller, but that isn't what you need.

Rather than presenting a second modal view controller, can you push your new viewController to the existing modal view controller's navigationController? This may give a nicer user experience anyway.

Or can you use a popover?


So here is what we did.

Since the view controller controlling the form sheet (B) does get -viewDidDisappear, we just add the presenting view controller (A) as a delegate, which we then notify by hand when -viewDidDisappear gets called on the (B) view controller.

The delegate definition looks like this:

@protocol FormSheetViewControllerDelegate

- (void)formSheetViewDidDisappear;

@end

We add a delegate to the FormSheetViewController:

@interface FormSheetViewController

@property (nonatomic, weak) id <FormSheetViewControllerDelegate> delegate;

@end

And we call -formSheetViewDidDisappear from the FormSheetViewController:

@implementation FormSheetViewController

- (void)viewDidDisappear:(BOOL)animated {
    [delegate formSheetViewDidDisappear];
}

@end

P.S.: Since iOS 5 and blocks, UIViewController has the method

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion

Which you could use to react to the dismissal of the form sheet view.

0

精彩评论

暂无评论...
验证码 换一张
取 消