【发布时间】:2017-04-14 10:26:26
【问题描述】:
我有一个表格视图和一个包含文本字段和多个按钮的视图。该视图位于屏幕底部,位于 UITableView 下方(作为标准消息面板)。当用户点击文本字段时,键盘出现,包括文本字段的视图向上移动。我还更改了表格视图的大小,缩短了它。一切都如我所愿。
但是,当我从这个视图控制器(用于查看图片)转到另一个视图控制器并返回时,该系统无法正常工作。键盘出现,但文本字段不上去。有时会有空白(因为有视图),但最后没有文本字段或按钮。
我的代码:
- (void) keyboardWasShown:(NSNotification *)notification {
// get keyboard height
NSDictionary* keyboardInfo = [notification userInfo];
NSValue* keyboardFrameEnd = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [keyboardFrameEnd CGRectValue];
self.keyboardHeight = keyboardRect.size.height;
// shorten tableview. so all of it will be visible
[self.chatTableViewBottomConstraint setConstant:self.tableViewBottomToLayoutConstraint + self.keyboardHeight-54.0];
[self.chatTableView setContentOffset:CGPointMake(0, CGFLOAT_MAX)]; // always the last item will be visible
// move textfield up
[self.textFieldViewBottomConstraint setConstant:+self.keyboardHeight-54.0];
[self.view bringSubviewToFront:self.textFieldView];
}
- (void) keyboardWillBeHidden:(NSNotification *)notification {
// restore tableview height and textfield position
[self.textFieldViewBottomConstraint setConstant:0.0f];
[self.chatTableViewBottomConstraint setConstant:self.tableViewBottomToLayoutConstraint];
}
在 UITableView 底部使用页脚对我的目标有好处,但是当表格视图为空时,此页脚会向上。这个问题不好。
那么,我错过了什么吗?为什么我的系统不能正常工作?
谢谢!
答案:问题不在于我的键盘方法。我找到了原因,它是关于我隐藏在其他视图控制器中的标签栏。我将它设置为不隐藏,一切正常。
换句话说,问题不在于键盘或文本字段。
【问题讨论】:
标签: ios objective-c uitableview keyboard uitextfield