开发者

How to Dismissing keyboard?

开发者 https://www.devze.com 2023-04-09 19:31 出处:网络
I do have Three TextField For Name Phone and Email. On selecting each textField keyboard will appears -(void)createdTextField{

I do have Three TextField

For Name Phone and Email.

On selecting each textField keyboard will appears

-(void)createdTextField{
    phoneField = [[UITextField alloc]initWithFrame:CGRectMake(225, 306, 90, 31)];
    [phoneField setPlaceholder:REQUIRED];
    [phoneField setBorderStyle:UITextBorderStyleRoundedRect];
    phoneField.delegate = self;
    phoneField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    phoneField.keyboardType = UIKeyboardTypeNumberPad;
    [phoneField setTag:10];
    [self.view addSubview:phoneField];

    [self.view addSubview:phoneField];
    nextPhoneField = [[UITextField alloc]initWithFrame:CGRectMake(325, 306, 142, 31)];
    [nextPhoneField setBorderStyle:UITextBorderStyleRoundedRect];
    nextPhoneField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    nextPhoneField.delegate = self;
    nextPhoneField.keyboardType = UIKeyboardTypeNumberPad;
    [nextPhoneField setTag:11];
    [self.view addSubview:nextPhoneField];



    nameField = [[UITextField alloc] initWithFrame:CGRectMake(225, 265, 242, 31)];
    [nameField setPlaceholder:REQUIRED];
    [nameField setBorderStyle:UITextBorderStyleRoundedRect];
    nameField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
//  [nameField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [nameField setTag:12];
    [self.view addSubview:nameField];

    eMailField = [[UITextField alloc]initWithFrame:CGRectMake(225, 347, 242, 31)];
    [eMailField setPlaceholder:REQUIRED];
    [eMailField setBorderStyle:UITextBorderStyleRoundedRect];
    eMailField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    eMailField.keyboardType = UIKeyboardTypeEmailAddress;
    [eMailField setAutocorrectionType:UITextAutocorrectionTypeNo];
    [eMailField setTag:13];

    [self.view addSubview:eMailField];

}

开发者_JAVA技巧- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}

@When to dismiss keyboard when typing return button in all four textField I need to dismiss the keyboard.

Its happen only for the phone no the remaining TextField.


I saw the code you paste. There is no delegate of the last two textfields. I think this is the reason.


Any time you want the keyboard hidden for a give field just do:

[myField resignFirstResponder];

As apparently myField is the field currently active.


How to Dismiss UITextField Keypad

[textField resignFirstResponder];

If you want to dismiss when user touch 'return' button, use this (Needed to set delegate and protocol, )

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}


after creation of urEachTextField


   urEachTextField = [[UITextField alloc] initWithFrame:CGRectMake(225, 265, 242, 31)];
    urEachTextField.delegate=self;

head file .h

    @interface urViewController : UIViewController<UITextFieldDelegate>
0

精彩评论

暂无评论...
验证码 换一张
取 消