Make Bottom UITableview Up With Keyboard

I have an application with UITableview and UITextView, so sometimes the keyboard gets up. Whenever the keyboard gets up, I can’t access the lower cells of table 3-4 because they are always stuck behind the keyboard. How can I make UITableView take up space above the keyboard while the keyboard is displayed?

Screenshothot of app

+8
ios objective-c cocoa-touch uitableview
source share
3 answers

I usually use https://github.com/michaeltyson/TPKeyboardAvoiding Which will automatically solve your usual problem But if you want to do some encoding manually

Use table setContentOffset or scrollToRowAtIndexPath

  CGPoint scrollPt = CGPointMake(textFieldRect.origin.x, textFieldRect.origin.y); [_tableView setContentOffset:scrollPt animated:YES]; UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview]; [_tableView scrollToRowAtIndexPath:[_tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES]; 
+10
source share

I had the same problem and here is my solution. Hope this helps.

 - (void) keyboardWillShow: (NSNotification*) aNotification { [UIView animateWithDuration: [self keyboardAnimationDurationForNotification: aNotification] animations:^{ CGSize kbSize = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; //change the frame of your talbleiview via kbsize.height } completion:^(BOOL finished) { }]; } - (void) keyboardDidShow: (NSNotification*) aNotification { [UIView animateWithDuration: [self keyboardAnimationDurationForNotification: aNotification] animations:^{ CGSize kbSize = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; //change the frame of your talbleiview via kbsize.height } completion:^(BOOL finished) { }]; } - (void) keyboardWillDisappear: (NSNotification*) aNotification { [UIView animateWithDuration: [self keyboardAnimationDurationForNotification: aNotification] animations:^{ //restore your tableview } completion:^(BOOL finished) { }]; } - (NSTimeInterval) keyboardAnimationDurationForNotification:(NSNotification*)notification { NSDictionary* info = [notification userInfo]; NSValue* value = [info objectForKey: UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval duration = 0; [value getValue: &duration]; return duration; } 

Add and remove event listeners.

 - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyboardDidShow:) name: UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyboardWillDisappear:) name: UIKeyboardWillHideNotification object:nil]; } - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver: self name: UIKeyboardWillShowNotification object: nil]; [[NSNotificationCenter defaultCenter] removeObserver: self name: UIKeyboardDidShowNotification object: nil]; [[NSNotificationCenter defaultCenter] removeObserver: self name: UIKeyboardWillHideNotification object: nil]; } 

Metin that several events will be received during one keyboard animation.

+4
source share

Try the following:

 CGRect frame = [tableViewer frame]; //assuming tableViewer is your tableview frame.size.height -= 200; //200 may be a bit off, should be height of keyboard [tableViewer setFrame:frame]; 

And the same thing, but change - = to + = when the keyboard disappears.

+1
source share

All Articles