First we know that Uialertview actually has a variety of styles, in Xcode, press and hold CMD, click Uialertview, and go to the header file we see:
1 typedef ns_enum (Nsinteger, Uialertviewstyle) {2 0 ,//Default style 3 Uialertviewstylesecuretextinput,//Encrypt text style 4 uialertviewstyleplaintextinput, //Normal text style 5 uialertviewstyleloginandpasswordinput//account password style 6 };
Second , we implement the Uialertview of the encrypted text style:
1. In the @interface section of the viewcontroller.m file, comply with <UIAlertViewDelegate> agreement:
1 #import " MoboViewController.h " 2 3 @interface moboviewcontroller () <UIAlertViewDelegate>45@end
2. Initialize an instance of Uialertview in the-(void) Viewdidload method and set its style to the encrypted text style.
1- (void) Viewdidload2 {3 [Super Viewdidload];4 5 //Initialize Alertview, set proxy to self6Uialertview *altview = [[Uialertview alloc]initwithtitle:[self Alttitle] message:[self AltMSG]Delegate: Self cancelbuttontitle:[self cancelbtntitle] otherbuttontitles:[self Otherbtntitle], nil];7 8 //Setting the Altview type9 [Altview setalertviewstyle:uialertviewstylesecuretextinput];Ten One //get Uitextfield . AUitextfield *TF = [Altview textfieldatindex:0]; - - //sets the keyboard type of the TextField. theTf.keyboardtype =Uikeyboardtypenumberpad; - - //Show Alertview - [Altview show]; + -}
3. Realization-(nsstring*) Alttitle,-(nsstring*) altmsg,-(nsstring*) Alttitle,-(nsstring*) Cancelbtntitle,-(nsstring*) Otherbtntitle method.
1 //return title2-(NSString *) alttitle{3 return @"Offline Notification";4 }5 6 //returns the body of the message7-(NSString *) altmsg{8 return @"your account is logged off-site, the password may be leaked, it is recommended to go to http://mobodemy.com to modify. ";9 }Ten One //Returns the Exit button caption A-(NSString *) Cancelbtntitle { - return @"Exit"; - } the - //return Login button title --(NSString *) Otherbtntitle { - return @"Re-login"; +}
4. Implement the Monitor button click Method
1 //Monitor Click-Time Proxy Method2- (void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) Buttonindex3 {4NSString *btntitle =[Alertview Buttontitleatindex:buttonindex];5 if([Btntitle isequaltostring:[self Cancelbtntitle]]) {6NSLog (@"you clicked the exit");7 }8 Else if([Btntitle isequaltostring:[self Otherbtntitle]]) {9NSLog (@"you clicked the Re-login button");Ten } One}
finally , to summarize, the other three styles of Alertview are basically implemented, modify the keyboard style, listening button click events, mainly remember the following several methods and techniques are good:
1. Create an instance of Uialertview and display it:
1 delegate: <# (ID) #> cancelbuttontitle:<# (NSString *) #> otherbuttontitles:<# ( NSString *), ...#>, nil]; 2 3 [Alertview show];
2, set the type of Alertview:
[Altview Setalertviewstyle:uialertviewstylesecuretextinput];
3, Get TextField keyboard, and set the type:
1 // get Uitextfield . 2 Uitextfield *TF = [Alertview textfieldatindex:0]; 3 4 // sets the keyboard type of the TextField. 5 tf.keyboardtype = uikeyboardtypenumberpad;//Set as numeric keypad
4, do not forget to abide by the agency agreement, to implement the Proxy method, otherwise it will error.
1 //Monitor Click-Time Proxy Method2- (void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) Buttonindex3 {4NSString *btntitle =[Alertview Buttontitleatindex:buttonindex];5 if([Btntitle isequaltostring:[self Cancelbtntitle]]) {6NSLog (@"you clicked the exit");7 }8 Else if([Btntitle isequaltostring:[self Otherbtntitle]]) {9NSLog (@"you clicked the Re-login button");Ten } One}
Ios7_ios7_ how to implement Uialertview and listen for click events (Other styles) _ How to modify the Uitextfield default keyboard style