views:

365

answers:

4

Hi everyone,

How can I detect the end of the animation of a modal view (when I do a dismiss)? (I'm talking about MFMailComposeViewController which is not created by myself...)

Thanks

+2  A: 

Your modal view controller has a -viewDidDisappear: method that is automatically invoked whenever the view is removed from the screen. You can override this method in your modal view controller to do whatever you like.

Also, you may want to consider implementing the -viewDidAppear: method in the view controller whose view gets revealed by your modal view disappearing.

Dave DeLong
I forgot to say that my modal view is not created by me... it is a MFMailComposeViewController
ncohen
A: 

I needed to do something after dismissing a modal view, and only when it is sure that the modal view is really gone (been completely dealloc-ed). So viewDidDisappear and its friends in the modal view were too early for me.

The easiest I found was to just delay my code with a NSTimer. When modal view calls its delegate and the delegate invokes removing the modal view, it also queues up the code to be run when the modal view is gone. The timing was something like 300ms or 400ms. (Is there a way to retrieve the actual timing from somewhere?)

Jaanus
I forgot to say that my modal view is not created by me... it is a MFMailComposeViewController
ncohen
A: 

Normally to be notified when an animation is complete you set a delegate by sending setAnimationDelegate: to the UIView class.

When a VC is dismissed using [someVC dismissModalViewControllerAnimated:YES] you can't set the animation delegate, but if you send NO instead and do your own animation of the VC's view you can set the delegate and be notified when the animation is completed.

progrmr
it seems too complicated for a modal view... I don't want to redo the animation!
ncohen
@progrmr: `+setAnimationDelegate:` is a class method, not an instance method.
KennyTM
@Kenny: you're right, I've corrected my answer, thanx!
progrmr
+1  A: 

You can subclass MFMailComposeViewController and overload its -viewDidDisappear:.

@interface MyCtrler : MFMailComposeViewController
@end
@implementation MyCtrler
-(void)viewDidDisappear:(BOOL)animated {
   [super viewDidDisappear:animated];
   // do anything you like
}
@end
KennyTM
yes but it is not when it disappears but when it's dealloc'd...
ncohen
@ncohen: It is not what?
KennyTM
I'm looking for something which is called when the controller is dealloc'd not when the view disappears!
ncohen