我有以下代码将信息发送到下一个UIViewController。在下一个UIViewController中,我有一个UITextField。当使用功能commentsTapped时(这意味着它将转到下一个UIViewController),它应该自动“选择”该UITextField并调出键盘。

这是我的代码:

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
    }
  }
}

有谁知道这是怎么做到的吗?

最佳答案

在您的commentsTableViewControllerviewDidLoad方法中添加以下内容:

override func viewDidLoad() {
  super.viewDidLoad()
  // Do any additional setup after loading the view.

  yourTextfield.becomeFirstResponder()
}

关于ios - 选择文本框并在显示ViewController之前调出键盘-Swift,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40131381/

10-14 21:30
查看更多