Disable return button of 'UITextField'

2

Is there any way, without gambiarras, to disable the Return button of a UITextField ?

I have a screen with two UITextField , one text and one numeric, I need the keyboard to be turned on directly and I need the Return button in the text field to be disabled, so that the keyboard does not close when I press it .

    
asked by anonymous 14.02.2014 / 01:52

2 answers

2

The way to disable the return button action is to use delegate as @Paulo replied. But, you can not quite simply lock the open keyboard in a view. This goes against good usability standards and against Apple's usability document.

I recommend that you make a check of which UITextField is making the call and act accordingly.

For example, if it is the text that called the return, change the focus to the numeric and, if it is numeric, pick up the keyboard.

- (BOOL) textFieldShouldReturn:(UITextField *)textField {
    if(textField == self.texto) {
        [self.numero becomeFirstResponder];   
    }else {
        [textField resignFirstResponder];
    }
    return NO;
}
    
14.02.2014 / 15:10
2

What you can do to prevent this is to use the delegate % with UITextField , for example:

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

At least iPhone , the "Return" button by itself has no automatic action until you define one in this delegate . In iPad , I believe the default function is textFieldShouldReturn: but you can prevent that too.

    
14.02.2014 / 12:24