Skip to content

IOS:UIAlertView

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.

축약하면, 기존에 비정상 UIAlertView의 오작동 출력을 방지한다.

Alert 출력 방법

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