Skip to content
Search

IOS:UIAlertView

lastmod 2021-04-01created 2014-03-255 edits

dismissWithClickedButtonIndex:animated:

In iOS 4.0, you may want to call this method whenever your application moves to the background. An alert view is not dismissed automatically when an application moves to the background. This behavior differs from previous versions of the operating system, where they were canceled automatically when the application was terminated. Dismissing the alert view gives your application a chance to save changes or abort the operation and perform any necessary cleanup in case your application is terminated later.

In short, it prevents a leftover abnormal UIAlertView from being displayed incorrectly.

How to Display an Alert

Use UIAlertView:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test Message" 
                                                  message:@"This is a sample"
                                                 delegate:nil
                                        cancelButtonTitle:@"OK" 
                                        otherButtonTitles:nil];
[alert show];
[alert release];

Sample Code

UIAlertView * alert = nil;
// ...
[alert dismissWithClickedButtonIndex:0 animated:YES]; // !?
// ...
alert = [[UIAlertView alloc] init];
[alert setTitle:@"Finish"];
[alert setMessage:[NSString stringWithFormat:@"Conversion takes %fs", [[NSDate date] timeIntervalSinceDate:_startDate]]];
[startDate release];
[alert addButtonWithTitle:@"OK"];
[alert setCancelButtonIndex: 0];
[alert show];
[alert release];

See also

Favorite site

author Zer0 sitemap