Search code examples
iosobjective-ciphoneios4

Scroll to new textfield when choosing a new textfield


I have followed apple's guide Managing keyboard

It works like a charm unless you are already writing in a textfield and tab in a new textfield.

This is the function in the example that take cares of the scrolling. But it's never being called because it's already up?

- (void)keyboardWasShown:(NSNotification*)aNotification;

Anyone know a good solution to this problem?


Solution

  • in .h

    CGSize keyboardSize;
    

    and

    - (void)keyboardWasShown:(NSNotification*)aNotification;
    

    in .m

    - (void)keyboardWasShown:(NSNotification*)aNotification {
        NSDictionary* info = [aNotification userInfo];
        if (info) {
                /* Can get keyboard Size */
                keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey]
        } 
    
        /* Animation code */
    
    }
    
    - (void)textFieldDidBeginEditing:(UITextField *)textField {
        activeField = textField;
        [self keyboardWasShown:[NSNotification notificationWithName:UIKeyboardDidShowNotification object:nil]];
    }
    

    Thanks to vakio.