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