Ios-uialertview and Uiactionsheet

Source: Internet
Author: User

Two big controls in iOS: Uialertview and Uiactionsheet

Uialertview is a message box that pops up in the center of the screen, which can be used to prompt a message or allow the user to select different options.

Uiactionsheet is a message box that pops up at the bottom of the screen and functions like Uialertview, but the two differ in their appearance as well as their location. In order to be able to respond to Uialertview and Uiactionsheet, the agent needs to be set up, and the corresponding agent needs to implement the corresponding protocol (uialertviewdelegate,uiactionsheetdelegate). Implement the following two functions

Called when a button is clicked. The view would be automatically dismissed following this call returns-(void) Alertview: (Uialertview *) Alertview Clickedbuttonat Index: (Nsinteger) buttonindex;//called when a button is clicked. The view would be automatically dismissed following this call returns-(void) Actionsheet: (Uiactionsheet *) Actionsheet clickedbu Ttonatindex: (Nsinteger) Buttonindex;


Sample code

  • Proxy Implementation Protocol
    @interface Viewcontroller:uiviewcontroller <uialertviewdelegate, uiactionsheetdelegate>

  • Main function Code
    -(Ibaction) Ontextfieldend: (ID) sender{[_texttime Resignfirstresponder]; Show dialog box # if 0 uialertview* alert = [[Uialertview alloc] initwithtitle:@ "Textcontend" Message:_texttime.text delegate:se        LF cancelbuttontitle:@ "OK" otherbuttontitles:@ "good", @ "Thanks", nil];    [Alert show]; [Alert release]; #else//Bottom Popup Dialog uiactionsheet* sheet = [[Uiactionsheet alloc] initwithtitle:@ "Actionsheet" delegate : Self cancelbuttontitle:@ "cancelbuttontitle" destructivebuttontitle:@ "Destructivebuttontitle" otherButtonTitles:@        "OtherButton1", @ "OtherButton2", nil];    [Sheet ShowInView:self.view]; [Sheet release]; #endif}//Button Press the response function-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger)        buttonindex{nsstring* strinfo = nil; Strinfo = [[NSString alloc] initwithformat:@ "You pressed the"%@ "button,%d buttons", [Alertview Buttontitleatindex:buttonindex],    Buttonindex]; uialertview* alert = [[Uialertview alloc]initwithtitle:@ "button response Agent function" Message:strinfo Delegate:nil Cancelbuttontitle:@ "determine" otherbuttontitles:nil];    [Alert show];    [Alert release]; [Strinfo release];} Response function when button pressed-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (nsinteger) buttonindex{NSString*        Strinfo = nil; Strinfo = [[NSString alloc] initwithformat:@ "You pressed the"%@ "button,%d buttons", [Actionsheet Buttontitleatindex:buttonindex],    Buttonindex]; uialertview* alert = [[Uialertview alloc]initwithtitle:@ "button response Agent function" Message:strinfo delegate:nil cancelbuttontitle:@ "        Determine "Otherbuttontitles:nil";    [Alert show];    [Alert release]; [Strinfo release];}

Ios-uialertview and Uiactionsheet

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.