I have a subclass of UITableViewController
that displays several rows (8 to be exact), where the top row is a custom cell that contains a UITextField
. When the view is loaded, I have the keyboard popup immediately by calling becomeFirstResponder
on that textfield
. This all worked fine until I upgraded from iOS 9 to iOS 10. Now the view jumps to the bottom of the view, with the keyboard covering my last two rows and my TextField
is off the visible area. When I comment out the becomeFirstResponder
call, the jumping goes away, but I lose my keyboard popup of course. This is what my code looks like...
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 {
....
Then my custom table view cell looks like this...
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)
}
...
Things I have tried:
- Calling
userInfoCell?.nameField.becomeFirstResponder()
inviewWillAppear()
- Calling
userInfoCell?.nameField.becomeFirstResponder()
inviewDidAppear()
- Calling
nameField.becomeFirstResponder()
inUserInfoTableViewCell.awakeFromNib()
. - Calling
tableView.scrollToRowAtIndexPath()
after the call touserInfoCell?.nameField.becomeFirstResponder()
. - removing
super.viewWillAppear()
in myviewWillAppear()
None of these have worked for me.