Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在展开segue之前添加If语句?_Ios_Swift - Fatal编程技术网

Ios 如何在展开segue之前添加If语句?

Ios 如何在展开segue之前添加If语句?,ios,swift,Ios,Swift,我有两个视图:第一视图和第二视图 在SecondView上,有一个文本字段和一个提交按钮。 如果用户单击提交按钮,请在返回FirstView之前检查textfield是否为空 在SecondView的故事板上,我通过按住Ctrl键并单击Submit按钮创建一个展开序列,然后拖动以退出并选择点击BacktoFirstView 在FirstViewController上: @IBAction func tapToBackToFirstView (segue: UIStoryboardSegue) {

我有两个视图:第一视图和第二视图

在SecondView上,有一个文本字段和一个提交按钮。 如果用户单击提交按钮,请在返回FirstView之前检查textfield是否为空

在SecondView的故事板上,我通过按住Ctrl键并单击Submit按钮创建一个展开序列,然后拖动以退出并选择
点击BacktoFirstView

在FirstViewController上:

@IBAction func tapToBackToFirstView (segue: UIStoryboardSegue) {


    }
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "backToFirstViewFromSecondView" {
            let destinationController = segue.destination as! FirstViewController
            destinationController.resultLabel.text = secondViewTextField.Text
        }
    }
在SecondViewController上:

@IBAction func tapToBackToFirstView (segue: UIStoryboardSegue) {


    }
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "backToFirstViewFromSecondView" {
            let destinationController = segue.destination as! FirstViewController
            destinationController.resultLabel.text = secondViewTextField.Text
        }
    }
在我的代码中,如果我单击Submit按钮,它总是转到FirstView。 如何添加IF语句来检查textfield是否为空?如果为空,则显示警报,不要转到FirstView

如果它不是空的,请转到FirstView


谢谢

在您的FirstView控制器上,您有了unwindseguemethod
点击BacktoFirstView
,它是从按钮操作右侧连接的?。现在将其移除,而不是通过iAction连接展开序列,只需从SecondViewController拖动到它自己的出口,就可以创建一个手动序列。为该文件指定一个
序列标识符

现在,连接IBAction与任何按钮一样正常工作。在此基于条件中调用performsguewithidentifier

@IBAction func tapToBackToFirstView(sender: AnyObject) {
    if //Add your condition here
        {performSegueWithIdentifier("segue identifier", sender: self)}
    else {
        //Do this
      }
}