[英]UITableViewController resizing TableView sporadically
I have a few UITableViewControllers
in my app. 我的应用程序中有一些
UITableViewControllers
。 I have UITextFields
in some of the UITableViewCells
. 我在某些
UITableViewCells
有UITextFields
。 Sometimes the tableView
resizes itself when the keyboard appears, but not always. 有时,当键盘出现时,
tableView
调整大小,但并非总是如此。
I've attached a couple examples. 我已经举了几个例子。 Both have a
UITextField
that are the current firstResponder
. 两者都有一个
UITextField
,它们是当前的firstResponder
。 I've dragged up for both screen shots to show the scroll indicator. 我都拖动了两个屏幕快照以显示滚动指示器。
The UITableViewController
on the left resized it's tableView
when the keyboard appeared, but the UITableViewController
on the right did not. 出现键盘时,左侧的
UITableViewController
调整为tableView
大小,但右侧的UITableViewController
没有。 What am I doing wrong? 我究竟做错了什么?
EDIT 编辑
Thanks to everyone for helping me on this problem. 感谢大家在这个问题上为我提供帮助。 Still hasn't been solved.
仍然没有解决。 They both have a
UINavigationController
as their parentViewController
. 它们都具有
UINavigationController
作为其parentViewController
。 The one on the right is the UINavigationControllers
topViewController
while the one on the left was presented from the topViewController
. 右边的一个是
UINavigationControllers
topViewController
而左边的一个是topViewController
呈现的。 Any help would be appreciated. 任何帮助,将不胜感激。
So, I've figured out a workaround: 因此,我想出了一种解决方法:
- (void)setContentInsetWithTextField:(UITextField *)textField
{
CGFloat keyboardHeight = 216;
CGFloat movement = (textField.isFirstResponder ? keyboardHeight : -keyboardHeight);
UIEdgeInsets contentInset = self.tableView.contentInset;
contentInset.bottom = contentInset.bottom + movement;
self.tableView.contentInset = contentInset;
}
Call this method in the textFieldDidBeginEditing
and the textFieldDidEndEditing
and it solves the problem! 在
textFieldDidBeginEditing
和textFieldDidEndEditing
调用此方法即可解决问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.