mskw
mskw

Reputation: 10348

how to go about detecting dismissModalViewControllerAnimated

Is there a way to implement your own mechanism to detect when dismissModalViewControllerAnimated disappears? I've tried viewdiddisappear, but this is not being called as I think it only called when subview are removed from a view. With the case of modals, I think iOS treats them differently.

Any ideas?

I would like my delegate to do some action after this modal view has been dismissed.

Thanks.

Upvotes: 1

Views: 518

Answers (4)

jerrylroberts
jerrylroberts

Reputation: 3454

Use NSNotificationCenter to post a notification before you dismiss the view controller. Add your other view controllers as observers. That's an easy way to broadcast events.

So before you dismiss:

[[NSNotificationCenter defaultCenter] postNotificationName:@"DismissModalViewController" 
                                                    object:nil];

[self dismissModalViewControllerAnimated:YES];

And then in your view controllers

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(yourCallback)
                                             name:@"DismissModalViewController" 
                                           object:nil];

The callback would be something like:

- (void) yourCallback
{
    // some code to run when modal view controller is dismissed
}

Upvotes: 1

mskw
mskw

Reputation: 10348

I found the issue.

The view controller that made this call, I forgot to set who the delegate was.

Upvotes: 0

barley
barley

Reputation: 4473

You can use the parent view controller's viewWillAppear. By parent view controller, I mean the receiver of presentViewController (or presentModalViewController)

Upvotes: 0

Dustin
Dustin

Reputation: 6803

Add a delegate method that is called right before dismissModalViewController

Upvotes: 0

Related Questions