IPhone DevelopmentUnderstandingUIALertViewAndUIActionSheetThe application is the content to be learned in this article.UIALertViewAndUIActionSheetFirst, let's look at the details.
1: Build a simple warning box:
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"
- message:@"message"
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [alert show];
- [alert release];
Here, it is just a button dialog box that runs in a modal form.
2: Of course, you can add multiple buttons in an alertView. The reference code is as follows:
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"
- message:@"message"
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:@"FirstButton",@"SecondButton",
- nil];
- [alert show];
- [alert release];
3: Determine which button to click and trigger different events based on different buttons:
AlertView has a delegate (UIAlertViewDelegate), which can be inherited and then called to process events.
Reference Code
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"
- message:@"message" delegate:self
- cancelButtonTitle:@"OK"
- otherButtonTitles:@"FirstButton",
- @"SecondButton",nil];
- [alert show];
- [alert release];
- //delegate
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(int)index
-
- {
- NSString *tt = [[NSString alloc] initWithFormat:@"%d",index];
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"
- message:tt
- delegate:self
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
4: manual cancellation dialog box
Reference code:
- [alert dismissWithClickedButtonIndex:0 animated:YES];