views:

217

answers:

1

Hello guys!

I have an UIViewController which was displayed by invoking the presentModalViewController method and now I want to dismiss it with the dismissModalViewControllerAnimated: . Everything works fine but is there any event or a delegate method which I can catch to handle the dismissing of my UIViewController?

+2  A: 

Typically since it is your code that is doing the dismissal, there is no need for an event. if you require one for some reason (decoupling, etc) then you can easily use the NSNotificationCenter.

// listen for an event
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDialogDimissed:) name:@"myapp_dialog_dismissed" object:nil];

- (void) onDialogDismissed:(NSNotification*)n
{
  NSLog(@"yay");
}

// raise an event
[[NSNotificationCenter defaultCenter] postNotificationName:@"myapp_dialog_dismissed" object:nil userInfo:nil];

It's probably worth mentioning that you can pass a NSDictionary* into userInfo and if all goes well will show up on the other end, so you don't have to create your own sub-classes or special event wrappers just to pass around data between events.

slf
ok, thank you for this, but I have one more problem, the notification as you wrote appears before the dismiss, then the viewcontroller is dismissed, but I want an event or something after the dismiss. Maybe can you solve this?
Infinity
you raise the event whenever you want. whatever code is dismissing your dialog is the code that should raise the event.... after the dismiss
slf
good to know ;)
Infinity