Daniel
Daniel

Reputation: 87

Is there a way to dismiss an alertview automatically after some time?

I'm looking for a way, to automatically dismiss an alert view after some time or after a task is done. Is there a possibility? (or another way to show a message for some time?)

Upvotes: 5

Views: 3523

Answers (2)

kennytm
kennytm

Reputation: 523504

You can call the -dismissWithClickedButtonIndex:animated: method to dismiss the alert view.

To dismiss it automatically, create an NSInvocation and then use -performSelector:withObject:afterDelay: to -invoke it.

Upvotes: 11

Macmade
Macmade

Reputation: 54010

UIAlertView has a method called:

- ( void )dismissWithClickedButtonIndex: ( NSInteger )buttonIndex animated:( BOOL )animated

You can call it on your UIAlertView object to simulate a button press.
To dismiss it automatically after some time, you will need something like an NSTimer, to check if the alert view is still displayed, and in such a case, dismiss it.

Upvotes: 0

Related Questions