Configuring the keyboard display interface for a UITextField or UITextView

I have a table with each cell containing a label and a text box. The problem is that when I go to edit the last row, the keyboard hides the bottom of the table and I donโ€™t see what is typing. How can I move my interface above the keyboard, so I see what is typing?

Thank you Mustafa

+6
cocoa-touch
source share
7 answers

You want to register your viewController for the UIKeyboardDidShowNotification and UIKeyboardWillHideNotification . When you receive them, you must adjust the borders of your table; the keyboard is 170 pixels high, so just decrease or increase the borders of your table accordingly, and it should fit the keyboard correctly.

+10
source share

This problem is complex depending on your user interface. Here I will talk about a scenario in which a UITextField or UITextview is in a UITableViewCell.

  • You need to use NSNotificationCenter to detect the UIKeyboardDidShowNotification event. see http://iosdevelopertips.com/user-interface/adjust-textfield-hidden-by-keyboard.html . You need to reduce the frame size of the UITableView so that it occupies only an area of โ€‹โ€‹the screen that is not covered by the keyboard.

    1. If you click UITableViewCell, the OS will automatically place the cell in the UITableView viewport. But this does not happen when you click on a UITextView or UITableViewCell, even if it is in a UITableViewCell.

You need to call

 [myTableView selectRowAtIndexPath:self.indexPath animated:YES scrollPosition:UITableViewScrollPositionBottom];` 

programmatically "touch" the cell.

If you implement both points, you will see the UITextView / Field position directly above the keyboard. Do not forget that the UITableViewCell where the UITableView / Field is located cannot be higher than the โ€œunclosedโ€ area. If this is not the case, there is a different approach for you, but I will not discuss it here.

+5
source share

Check this question: List of editable text fields UITableView

+1
source share

Just make sure you have enough scroll space below this. Because, to my knowledge, the iPhone automatically adjusts and displays a focused text field at the time its keyboard appears.

0
source share

Deleting / commenting out lines in which the correct height changes seems to solve the problem. Thanks.

Modified Code:

 # define kOFFSET_FOR_KEYBOARD 150.0 // keyboard is 150 pixels height // Animate the entire view up or down, to prevent the keyboard from covering the author field. - (void)setViewMovedUp:(BOOL)movedUp { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; // Make changes to the view frame inside the animation block. They will be animated instead // of taking place immediately. CGRect rect = self.view.frame; CGRect textViewRect = self.textViewBeingEdited.frame; CGRect headerViewRect = self.headerView.frame; if (movedUp) { // If moving up, not only decrease the origin but increase the height so the view // covers the entire screen behind the keyboard. rect.origin.y -= kOFFSET_FOR_KEYBOARD; // rect.size.height += kOFFSET_FOR_KEYBOARD; } else { // If moving down, not only increase the origin but decrease the height. rect.origin.y += kOFFSET_FOR_KEYBOARD; // rect.size.height -= kOFFSET_FOR_KEYBOARD; } self.view.frame = rect; [UIView commitAnimations]; 

}

0
source share
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardDidHideNotification object:nil]; keyboardVisible = NO; - (void)keyboardWasShown:(NSNotification *)aNotification { if ( keyboardVisible ) return; if( activeTextField != MoneyCollected) { NSDictionary *info = [aNotification userInfo]; NSValue *aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey]; CGSize keyboardSize = [aValue CGRectValue].size; NSTimeInterval animationDuration = 0.300000011920929; CGRect frame = self.view.frame; frame.origin.y -= keyboardSize.height-300; frame.size.height += keyboardSize.height-50; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; self.view.frame = frame; [UIView commitAnimations]; viewMoved = YES; } keyboardVisible = YES; } - (void)keyboardWasHidden:(NSNotification *)aNotification { if ( viewMoved ) { NSDictionary *info = [aNotification userInfo]; NSValue *aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey]; CGSize keyboardSize = [aValue CGRectValue].size; NSTimeInterval animationDuration = 0.300000011920929; CGRect frame = self.view.frame; frame.origin.y += keyboardSize.height-300; frame.size.height -= keyboardSize.height-50; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; self.view.frame = frame; [UIView commitAnimations]; viewMoved = NO; } keyboardVisible = NO; } 
0
source share
 tabelview.contentInset = UIEdgeInsetsMake(0, 0, 210, 0); [tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:your_indexnumber inSection:Your_section] atScrollPosition:UITableViewScrollPositionMiddle animated:NO]; 

try this my coding, this will help for u

0
source share

All Articles