Reputation: 21
I am having problem with the textfield input. In the 'CommentviewController' I have a scrollable tableview to display the previous comments, and at the bottom is a UItextField for the user to enter the comment and post it. The problem is: when I tried to type in the textfield and the keyboard is toggled, the text jumps up and down while I 'm typing. For example, the first char I typed is above the keyboard, and the second is below and behind the keyboard. Anybody has any idea about the cause? The test device is a 64 GB itouch5, and the code is written in objective C, and I am using the Xcode 6.3.2.
<i>`- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
theKBSize = kbSize;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height - 10, 0.0);
self.tvComment.contentInset = contentInsets; self.tvComment.scrollIndicatorInsets = contentInsets;
CGRect uvFrame = _uvComment.frame;
uvFrame.origin.y = self.view.frame.size.height - kbSize.height - _uvComment.frame.size.height; _uvComment.frame = uvFrame; } `</i>
<i> `- (void)keyboardWillBeHidden:(NSNotification*)aNotification {
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
_tvComment.contentInset = contentInsets;
_tvComment.scrollIndicatorInsets = contentInsets;
}`</i>
<i>`- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(string==nil || [string length]<1) {
[self.btnSend setEnabled: NO];
}else {
[self.btnSend setEnabled: YES];
}
return YES;
}`</i>
Upvotes: 2
Views: 846
Reputation: 503
Are you changing the scroll position of the tableView
?
A UITableView
will automatically scroll so that the UITextField
is not hidden by the keyboard when selected and the keyboard pops up. If you are changing the scroll position, that could be interfering with the auto scroll behavior.
Upvotes: 1