Ios 在某些情况下如何取消一个序列(如果/否则)?

Ios 在某些情况下如何取消一个序列(如果/否则)?,ios,swift,segue,Ios,Swift,Segue,我正在创建一个应用程序。在某个视图中,有几个文本字段,用户在其中输入数字,然后按下按钮,然后传输到下一个视图控制器 如果一个人点击按钮,一个或多个文本字段为空,segue将取消,该如何设置 以下是我迄今为止在该领域的代码: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if saveButton === sender { let name = nameTextFi

我正在创建一个应用程序。在某个视图中,有几个文本字段,用户在其中输入数字,然后按下按钮,然后传输到下一个视图控制器

如果一个人点击按钮,一个或多个文本字段为空,segue将取消,该如何设置

以下是我迄今为止在该领域的代码:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if saveButton === sender {
        let name = nameTextField.text ?? ""

        // Set the meal to be passed to MealListTableViewController after the unwind segue.
        meal = Meal(name: name)

    }

   if calcButton === sender {

    if weightInKilos.text == "" && percentOfDehydration.text == "" && ongoingLosses.text == "" && factor.text == "" {

        let alertController = UIAlertController(title: "Fields were left empty.", message:
            "You left some fields blank! Please make sure that all fields are filled in before tapping 'Calculate'.", preferredStyle: UIAlertControllerStyle.Alert)
        alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))

        self.presentViewController(alertController, animated: true, completion: nil)

    }

    else {
        let DestViewController: ftrViewController = segue.destinationViewController as! ftrViewController

        let weightInt: Int? = Int(weightInKilos.text!)
        let dehydrationInt: Int? = Int(percentOfDehydration.text!)
        let lossesInt: Int? = Int(ongoingLosses.text!)
        let factorInt: Int? = Int(factor.text!)

        let lrs24Int = (30 * weightInt! + 70) * factorInt! + weightInt! * dehydrationInt! * 10 + lossesInt!

        let lrsPerHourint = lrs24Int / 24

        DestViewController.lrsHr = "\(lrsPerHourint)"
        DestViewController.lrs24Hrs = "\(lrs24Int)"
    }
    }
}

在打电话给segue之前,你必须检查你需要的一切

所以,用户写下答案,你检查是否一切正常,如果一切正常,继续,否则,你通知用户并要求重新键入信息


明白了吗?

哪里有运行
performsgue的代码,或者您是直接在情节提要中执行的?使用函数shoulderforsegue,它返回一个bool,指示是否应该执行segue