0

I am trying to find what delegate/protocol or even notification is called when an alert view is hidden or shown. Do these events trigger a notification or callback that I can listen for?

I know the UIAlertView protocol, but that's not what I am looking for, I am looking for the actual display and hide events to perform actions after they are completed.

Does this exist?

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
Speckpgh
  • 3,332
  • 1
  • 28
  • 46

2 Answers2

1

If you want to know about AlertViews you've presented yourself, you're looking for UIAlertViewDelegate protocol

didPresentAlertView: and alertView:didDismissWithButtonIndex:

If you want to know when an AlertView has been shown by the OS, you can try UIWindowDidBecomeVisibleNotification and UIWindowDidBecomeHiddenNotification in the UIWindow class reference, then check if the windowLevel property is equal to UIWindowLevelAlert

mspensieri
  • 3,501
  • 15
  • 18
  • i think that was meant, when he said "I know the UIAlertView protocol, but that's not what I am looking for" – lootsch Apr 05 '14 at 20:43
  • Thank you the didbecomvisible notification hidden notification were what I was looking for... Is there a more unified document regarding notifications that are sent? I assumed this, and other notifications I would need exist, but finding documentation about them seems hap hazard at best. – Speckpgh Apr 06 '14 at 11:01
  • 1
    @user282172 : **`UIWindowDidBecomeVisibleNotification` & `UIWindowDidBecomeHiddenNotification` are not `UIAlertView` specific notifications**. They're `UIWindow` specific and hence these notifications will be posted when the app is shown/hidden i.e. app launch / app goes to background / app comes in foreground. It has nothing to do with `alertView` being shown or hidden. **It's just an indirect way to check**. There are **No** `UIAlertView` notifications (_kindly don't downvote answers without understanding the specifics_) – staticVoidMan Apr 06 '14 at 13:07
  • I downvoted your answer static, because you clearly didn't read my question. You cited the UIAlertView Protocol as an answer when I clearly stated in my question that I was aware of it and that it was not providing what I was seeking. – Speckpgh Apr 06 '14 at 13:31
  • @user282172 : my answer was no different than the comment above (_only difference, i assumed you were aware of Apple's notification naming convention that if the notification name begins with `UIWindow`, it's a `UIWindow` notification. If it begins with `UIKeyboard` it's a `UIKeyboard` notification_) PS: the downvote didn't bother me, it was the invalidity of the downvote. A downvote + comment would have been appreciated. – staticVoidMan Apr 06 '14 at 13:42
0

An easy way to check NSNotifications is adding that code to your AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification:) name    :nil object:nil];

    return YES;
}

-(void)notification:(NSNotification*)notification
{
    NSLog(@"Notification name is %@, \n sent by %@\n\n",[notification name], [[notification object] description] );
}

I tested this code triggering UIAlertViews and I never receive an NSNotification related to.
So probably there aren't NSNotificationrelated to UIAlertViews.

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81