How to disable keyboard appearing when hitting on

2020-06-02 09:43发布

I have a text field , and i need when the user presses it to show a custom picker.

The picker is shown fine , but the problem is that the keyboard appears on the bottom and i dont want that.

This is an iPad project which i am trying to convert from my iphone one. On the iPhone , this works well and the keyboard is always hidden.

What could i be missing/forgetting to do here ?

EDIT


For future reference what actually happened here , was that in fact both times (iphone & ipad) the keyboard was not hidden. I just thought that it was hidden in the iphone because my picker , which was popping from the bottom was hiding the keyboard as it was on top of it. But on ipad this wasnt the case.

Anyway i fixed it , using the delegate method suggested below.

Caution , i accepted this answer cause it was the one answering specifically what i wanted. The rest of the answers are correct and my considered better for other implementations.

8条回答
Viruses.
2楼-- · 2020-06-02 10:26
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    // Here you can do for Specific text Field by 
    if (textField==(the text field you don't want to show keyboard)) {
        NSLog(@"don't show keyboard");
        return NO;
    }
    else {
        return YES;
    }
}
查看更多
何必那么认真
3楼-- · 2020-06-02 10:29
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if(textfield == yourtextField)
    {
        [textfield resignFirstResponder];
        // Show you custom picker here....
        return NO;
    }     
}

and you need to implement the uitextfielddelegate in the controller.

and give assign the delegate to yourtextField.

查看更多
登录 后发表回答