IOS-UIAlertView and UIActionSheet

Source: Internet
Author: User

IOS-UIAlertView and UIActionSheet
Two controls in IOS: UIAlertView and UIActionSheet

UIAlertView is a message box that appears in the center of the screen. This message box can be used for message prompts or different options.

UIActionSheet is a message box popped up at the bottom of the screen. Its function is similar to that of UIAlertView. However, apart from the different positions, the two have different appearances. In order to be able to respond to UIAlertView and UIActionSheet, you need to set the proxy, and the corresponding proxy needs to implement the corresponding protocol (UIAlertViewDelegate, UIActionSheetDelegate ). Implement the following two functions:

// Called when a button is clicked. The view will be automatically dismissed after this call returns- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;// Called when a button is clicked. The view will be automatically dismissed after this call returns- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;


Sample Code

Proxy Implementation Protocol
@interface ViewController : UIViewController 
 

Main Function Code
-(IBAction) onTextFieldEnd :( id) sender {[_ textTime resignFirstResponder]; // displayed dialog box # if 0 UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "TextContend" message: _ textTime. text delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: @ "Good", @ "Thanks", nil]; [alert show]; [alert release]; # else // the pop-up dialog box at the bottom of the dialog box UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle: @ "ActionSheet" delegate: self cancelButtonTitle: @ "cancelButtonTitle" comment: @ "OtherButton1", @ "OtherButton2", nil]; [sheet showInView: self. view]; [sheet release]; # endif} // response function-(void) alertView: (UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {NSString * strInfo = nil; strInfo = [[NSString alloc] initWithFormat: @ "you have pressed the [% @] button, the % d button", [alertView buttonTitleAtIndex: buttonIndex], buttonIndex]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "button response proxy function" message: strInfo delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show] [alert release]; [strInfo release];} // response function-(void) actionSheet :( UIActionSheet *) actionSheet clickedButtonAtIndex :( NSInteger) buttonIndex {NSString * strInfo = nil; strInfo = [[NSString alloc] initWithFormat: @ "you have pressed the [% @] button, the % d button", [actionSheet buttonTitleAtIndex: buttonIndex], buttonIndex]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "button response proxy function" message: strInfo delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show] [alert release]; [strInfo release];}

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.