如果Condition在执行segue之前为True

时间:2018-10-22 02:34:45

标签: ios swift segue

我正在使用segue进行从ViewController BViewController A的过渡,同时我正在使用segue将数据从ViewController B传递到ViewController A。我已经构造了代码,其中用户将点击backbutton并使用alert controller执行SCLAlertView cocoapods。在进入下一个ViewController之前,它会提示this alert,但是当我运行它时,segue会自动执行而不先检查条件,并且它不会执行alert controller。我的代码在下面供您参考。希望您能对此有所帮助,因为我是新手,我进行了研究,但似乎看不到适用于我的问题的解决方案。谢谢。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showVCA" {
        if let vc_A = segue.destination as? ViewControllerA {
            vc_A.validPincode = validPincode
            vc_A.participants = participants
            vc_A.event = event
        }
    }
}



 @IBAction func backbutton(_ sender: UIButton) {
    let alert = SCLAlertView(appearance: confirmationAppearance)
    _ = alert.addButton("Leave", action: {
        self.dismiss(animated: true, completion: nil)
        self.performSegue(withIdentifier: "showVCA", sender: sender)

    })
    _ = alert.addButton("Stay", action: { })
    _ = alert.showError("Confirmation", subTitle: "Are you sure you want to leave this page?")

}

2 个答案:

答案 0 :(得分:0)

一旦.carousel { background-color: #ddd; }表示您已经执行代码以移至下一个ViewController,则应在<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> <div id="carousel-1" class="carousel slide"> <div class="carousel-inner"> <div class="carousel-item active"> Slide 1 </div> <div class="carousel-item"> Slide 2 </div> <div class="carousel-item"> Slide 3 </div> </div> <a class="carousel-control-prev d-none" href="#carousel-1" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next d-none" href="#carousel-1" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div>之前进行验证。

performSegue

答案 1 :(得分:0)

您的backbutton()函数似乎无法呈现 警报控制器(通过调用SCLAlertView的众多showXXX()函数之一),所以什么也不会曾经被展示过。您的按钮是否可能连接到视图控制器的“出口”而不是操作?

enter image description here