Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know when dismissModalViewControllerAnimated is initiated and also when it is done?

Is there a way to know when the dismissModalViewControllerAnimated is initiated and when it is completed (such as the idiom for viewWillAppear and viewDidAppear)? Unlike other animations, this one doesn't seem to have a delegate that tells you.

like image 493
Boon Avatar asked Jun 13 '09 01:06

Boon


3 Answers

Yes, and easier than you think.

When dismissModalViewControllerAnimated: is called, the underlying view (the one about to appear) will receive a viewWillAppear message and a viewDidAppear message.

Caveat: make sure your view controllers are hooked up properly or these messages get lost.

like image 99
Corey Floyd Avatar answered Nov 03 '22 21:11

Corey Floyd


I am afraid viewWillAppear and viewDidAppear don't always work. on iPhone they do, on iPad they may not. if the UIViewController presented is not presented in full screen (if it is presented as a form sheet for example) the parent view will not receive the viewWillAppear or viewDidAppear lifecycle functions. unfortunately the only way i found is to make my own delegate message to be called when the dismissModalViewControllerAnimated is called (ether by reference or with a notification)

like image 24
elad s Avatar answered Nov 03 '22 20:11

elad s


You can use the view appearance methods. And if you need something to happen after the animation completes, you can use [object performSelector:@selector(selector) withObject:anotherObject afterDelay:0]. I don't know exactly why, but the action will be scheduled on the current run loop, but after the animation completes.

like image 1
Victor Bogdan Avatar answered Nov 03 '22 20:11

Victor Bogdan