1

I have 10 textfields on tableview that tableview scrolling disabled.

How to handle keyboard avoiding textfields.

The Following is what I have tried with

// Register notification when the keyboard will be show

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasShown:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

// Register notification when the keyboard will be hide
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillBeHidden:)
                                             name:UIKeyboardWillHideNotification
                                           object:nil];

pragma mark - keyboard notification (Called when the UIKeyboardDidShowNotification is sent.)

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    guestRechargeTableView.contentInset = contentInsets;
    guestRechargeTableView.scrollIndicatorInsets = contentInsets;

    // If active text field is hidden by keyboard, scroll it so it's visible
    // Your app might not need or want this behavior.
    CGRect aRect = self.view.frame;
    aRect.size.height -= kbSize.height;

    if (!CGRectContainsPoint(aRect, activeField.frame.origin) )
 {

        [guestRechargeTableView scrollRectToVisible:activeField.frame animated:YES];

    }
}

// Called when the UIKeyboardWillHideNotification is sent

- (void)keyboardWillBeHidden:(NSNotification*)aNotification

{

    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    guestRechargeTableView.contentInset = contentInsets;
    guestRechargeTableView.scrollIndicatorInsets = contentInsets;

}

This is working but not proper when selecting on textfield and moves up.Provide solution for that or any other alternative answer..

Happy Coding....

Aruna kumari
  • 329
  • 1
  • 11

0 Answers0