UIALertView and UIActionSheet applications in iPhone development (1)

Source: Internet
Author: User

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:

 
 
  1. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"  
  2. message:@"message"  
  3.        delegate:nil   
  4.       cancelButtonTitle:@"OK"  
  5.       otherButtonTitles:nil];  
  6. [alert show];  
  7. [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:

 
 
  1. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"   
 
 
  1.   message:@"message"  
  2.   delegate:nil   
  3.   cancelButtonTitle:@"OK"  
  4.   otherButtonTitles:@"FirstButton",@"SecondButton",  
  5.    nil];  
  6. [alert show];  
  7. [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

 
 
  1. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"   
  2.            message:@"message" delegate:self   
  3.            cancelButtonTitle:@"OK"        
  4.            otherButtonTitles:@"FirstButton",  
  5.            @"SecondButton",nil];  
  6. [alert show];  
  7. [alert release];  
  8. //delegate   
  9. -(void)alertView:(UIAlertView *)alertView  clickedButtonAtIndex:(int)index  
  10.  
  11. {  
  12.         NSString *tt = [[NSString alloc] initWithFormat:@"%d",index];  
  13. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"xingchen"  
  14. message:tt  
  15.   delegate:self   
  16.   cancelButtonTitle:@"OK"  
  17.   otherButtonTitles:nil];  
  18. [alert show];  
  19. [alert release];  

4: manual cancellation dialog box

Reference code:

 
 
  1. [alert dismissWithClickedButtonIndex:0 animated:YES]; 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.