Ios7_ios7_ how to implement Uialertview and listen for click events (Other styles) _ How to modify the Uitextfield default keyboard style

Source: Internet
Author: User

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

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.