Disable Return button of`Uitextfield`

Asked

Viewed 237 times

2

Is there any way, no whining, to disable the Return button of a UITextField?

I have a screen with two UITextField, a text and a numeric, I need the keyboard to be activated directly and I need the Return button of the text field to be disabled, so that the keyboard does not close when pressing it.

2 answers

2

What you can do to prevent this is to use the delegate textFieldShouldReturn: of Uitextfield, so for example:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return NO;
}

At least in the iPhone, the "Return" button itself has no automatic action, until you set one in this same delegate. In the iPad, I believe that the standard function is [textField resignFirstResponder] but you can prevent that too.

2


The way to disable the action of the Return is to use delegate as @Paulo replied. But, you cannot simply lock the open keyboard in a view. This goes against good usability standards and against Apple’s usability document.

I recommend that you do a check of which Uitextfield is making the call and acting accordingly.

For example, if it is the text that called the Return, change the focus to the numeric and, if it is the numeric, collect the keyboard.

- (BOOL) textFieldShouldReturn:(UITextField *)textField {
    if(textField == self.texto) {
        [self.numero becomeFirstResponder];   
    }else {
        [textField resignFirstResponder];
    }
    return NO;
}
  • Got it... in my case I’m with this problem exactly because the numeric keyboard does not have the Return button... so to avoid the difference, I was thinking about turning off the alpha keyboard button and let create the bar on top of keyboards...

  • @Davidbatistadasilva, the best solution to enable navigation in a Uitextfield numeric is actually add a button on the keyboard, through the property inputAccessoryView. If you need help with this, open a question that puts an example code.

  • Dude, I created a new question for the button question on add a button on the Uitextfield. Follow the link [http://answall.com/questions/6199/como-addir-botao-no-keyboard-numerico-no-ios]

  • I came to see this question. But when I saw it, the question had already been answered. And, from what I saw, you found the resolution.

  • Oh man, thanks. I wanted to confirm if this was your solution to identify the best! rs It was really worth!

  • 1

    I would give the same answer that Julio gave. Even, I believe that using inputAcessoryView is a better option than inserting a button over the number pad. This is because the Acessoryview is a known and applied market standard.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.