Reputation: 467
I have the following code that is sending information to the next UIViewController
. In the next UIViewController
I have a UITextField
. When the function commentsTapped
is being used (which means it will go to the next UIViewController
), it should automatically "select" the UITextField
and bring up the keyboard.
Here is my code:
func commentsTapped(cell: updateTableViewCell) {
let allDataSend = cell.pathDB
self.performSegueWithIdentifier("showComments", sender: allDataSend)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showComments" {
if let nextVC = segue.destinationViewController as? commentsTableViewController {
nextVC.dataGotten = sender! as! String
}
}
}
Does anyone know how to do that?
Upvotes: 2
Views: 2134
Reputation: 3219
In your commentsTableViewController
's viewDidLoad
method add this:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
yourTextfield.becomeFirstResponder()
}
Upvotes: 1
Reputation: 2945
This way, you will see the keyboard appear after the view controller is loaded:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.textField.becomeFirstResponder()
}
Upvotes: 2