Question

I have a UITextField thats currently in a UITableViewCell, when you select the UITextField the UIkeyboard automatically comes up.

I would like to know how I can just ignore the return key when its pressed.. there is a feature I have no implemented yet to skip UITextFields its causing me some errors and before I preview my app I would like to disable it to avoid any confusion.

Was it helpful?

Solution

Sure, you'll need to use UITextFieldDelegate, specifically, textFieldShouldReturn:. All you have to do is specify that your class will conform to this protocol in your interface, and specify that this class as the delegate on the textfield's delegate property and you're good to go. That is, after returning no from textFieldShouldReturn:. Or of course, this can be done conditionally.

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (someCondition == YES) {
        return NO;
    }
    return YES;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top