在UITextfield上发生事件内部触摸时导航到另一个视图

时间:2016-07-14 13:29:34

标签: swift uitableview viewcontroller

我已将segue的标识符从ViewcontrollerA设置为ViewcontrollerB。但是下面的代码不起作用:

 class ViewcontrollerA: UIViewController {


 @IBOutlet weak var Tasks: UITextField!

 override func viewDidLoad() {
 super.viewDidLoad()

 // Do any additional setup after loading the view.
 }


 @IBAction func move(sender: AnyObject) {

 self.performSegueWithIdentifier("move", sender: sender)

 }

}

ViewController被“点击”时,有没有办法导航到第二个UITextfield

任何帮助都会非常感激!

2 个答案:

答案 0 :(得分:1)

假设您已经提供了 segue标识符 segue kind

  

替换func move:

 @IBAction func move(sender: AnyObject) {

 self.performSegueWithIdentifier("move", sender: self)

 }
  

添加以下代码:

  override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
        if identifier == "move" {

            return true
        }
        return false
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "move" {
            let vc = segue.destinationViewController as! ViewcontrollerB
            // you can additional work here with navigating VC Object
        }
    }

答案 1 :(得分:0)

如果您希望SecondViewController继续点击UITextField,那么您可以使用textFieldDidBeginEditing的委托方法UITextField

func textFieldDidBeginEditing(textField: UITextField) {
    self.performSegueWithIdentifier("SegueIdentifier", sender: self)
}