我有一个UITableViewController
的子类,它显示了几行(确切地说是8行),其中第一行是一个包含UITextField
的自定义单元格。加载视图时,我立即通过调用becomeFirstResponder
对该textfield
键盘弹出。这一切工作正常,直到我从iOS 9升级到iOS 10。现在视图跳转到视图的底部,键盘覆盖了我的最后两行,而我的TextField
不在可见区域。当我注释掉becomeFirstResponder
呼叫时,跳跃消失,但当然我失去了键盘弹出。这是我的代码看起来像......iOS 10 - UITableViewController在加载时滚动到底部
class UserProfileTableViewController: UITableViewController {
private var userInfoCell: UserInfoTableViewCell?
...
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == 0 {
userInfoCell = tableView.dequeueReusableCellWithIdentifier("userInfoCell", forIndexPath: indexPath) as? UserInfoTableViewCell
if !editMode {
userInfoCell?.nameField.becomeFirstResponder()
}
return userInfoCell!
}
else if indexPath.section == 1 {
....
然后我自定义表格视图单元格看起来像这样...
class UserInfoTableViewCell: UITableViewCell, UITextFieldDelegate,, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var nameField: UITextField!
@IBOutlet weak var photoImageView: UIImageView!
...
override func awakeFromNib() {
super.awakeFromNib()
// listen for when user touches a textfield
nameField.delegate = self
...
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
...
事情我已经尝试:
- 调用
userInfoCell?.nameField.becomeFirstResponder()
在viewWillAppear()
- 调用
userInfoCell?.nameField.becomeFirstResponder()
inviewDidAppear()
- 致电
nameField.becomeFirstResponder()
在UserInfoTableViewCell.awakeFromNib()
。 - 拨打
userInfoCell?.nameField.becomeFirstResponder()
后致电tableView.scrollToRowAtIndexPath()
。 - 去除
super.viewWillAppear()
在我的这些viewWillAppear()
都没有为我工作。
试试这个:'让细胞= tableView.dequeueReusa .....'/'回报cell' –
感谢您的建议,但没有不幸的是,这样做。我得到相同的滚动到底部问题。 – Coder1224
嗯,我是否堆栈堆栈溢出? – Coder1224