Setting the return key

April 25th, 2011
#ui

When I wanted to add a Done/Next key to the keyboard I found it surprisingly hard to find out how this was possible. After much research I stumbled upon the solutions that you go through the textfield to set the button.

Done

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
      textField.returnKeyType = UIReturnKeyDone;
}

Next

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
      textField.returnKeyType = UIReturnKeyNext;
}

Skip onto next field

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
   // _firstTextField is the textfield we are moving from
   //_secondTextField is the textfield we are moving to
    if ([textField isEqual:_firstTextField] && UIReturnKeyNext == textField.returnKeyType) {
        [_secondTextField becomeFirstResponder];
    }
    
    return YES;
}

What do you think? Let me know by getting in touch on Twitter - @wibosco