#import "ViewController.h" @interface ViewController () <uitextfielddelegate>@ property (weak, nonatomic) IBOutlet UITextField *usernameTextfield; @property ( weak, nonatomic) IBOutlet UITextField *passwordTextfield; @property (weak, nonatomic) IBOutlet UIButton *loginBtn; @end @implementation viewcontroller- (void) Viewdidload { [super viewdidload]; // do any additional setup after loading the view, typically from a nib. //setting Usernametextfield and Passwordtextfield related properties //setting usernameTextfield keyboard type /* typedef ns_enum (Nsinteger, uikeyboardtype) { uikeyboardtypedefault, // default type for the current input method. Uikeyboardtypeasciicapable, // displays a keyboard which can enter ascii characters, non-ascii keyboards remain active UIKeyboardTypeNumbersAndPunctuation, // numbers and assorted punctuation. uikeyboardtypeurl, // A type optimized for URL entry (shows . / .com prominently) . uikeyboardtypenumberpad, //&nBsp a number pad (0-9) . suitable for pin entry. uikeyboardtypephonepad, // A phone pad (1-9, *, 0, #, with letters under The numbers) . uikeyboardtypenamephonepad, // A type optimized for entering a Person ' s name or phone number. uikeyboardtypeemailaddress, // a type optimized for multiple email address entry (shows space @ . prominently). uikeyboardtypedecimalpad ns_enum_available_ios (4_1), // a number pad&nbsP;with a decimal point. uikeyboardtypetwitter ns_enum_ Available_ios (5_0), // a type optimized for twitter text entry (easy access to @ #) Uikeyboardtypewebsearch ns_enum_available_ios (7_0), // a default keyboard type with url-oriented addition (shows space . prominently). UIKeyboardTypeAlphabet = uikeyboardtypeasciicapable, // deprecated }; */ // self.usernametextfield.keyboardtype = uikeyboardtypenumberpad; //Setting the returnkey s of Usernametextfieldelf.usernametextfield.returnkeytype = uireturnkeynext; //You must allow this class to support the protocol before setting up the agent, and set the proxy to itself self.usernameTextfield.delegate = self; //Settings usernameTextfield self.passwordTextfield.keyboardType = UIKeyboardTypeEmailAddress; self.passwordTextfield.returnKeyType = UIReturnKeyDone; self.passwordtextfield.delegate =self; //makes the password you enter into a small origin. and general applications are doing so self.passwordTextfield.secureTextEntry = YES; }- (void) didreceivememorywarning { [super didreceivememorywarning] ; // dispose of any resources that can be Recreated.} - (ibaction) clickloginbtn: (Uibutton *) Sender { nslog (@ "Login successful");} #pragma mark - UITextFieldDelegate- (BOOL) Textfieldshouldreturn: (uitextfield *) textfield{ if (Textfield == self.usernametextfield) { //self.usernametextfield abandons the first responder, while Self.passwordtextfield becomes the first responder [self.usernameTextfield resignFirstResponder]; [self.passwordtextfield becomefirstresponder]; } else if (Textfield == self.passwordtextfield) { //self.passwordtextfield discards the first responder and calls the login function [ self.passwordtextfield resignfirstresponder]; [ Self.loginbtn sendactionsforcontrolevents:uicontroleventtouchupinside]; //[self clickloginbtn:self.loginbtn]; } return yes;} @end
What happens when you click the ENTER key on the iOS keyboard