how to perform Condition check, before segue unwind

后端 未结 2 1636
青春惊慌失措
青春惊慌失措 2021-01-06 09:41

VC1 segues to VC3 which has a keypad and predetermined lowest number acceptable entered into a label. User can either add a number to the end of th

相关标签:
2条回答
  • 2021-01-06 10:18

    I found a good answer in this SO post here.

    The trick is to override shouldPerformSegueWithIdentifier in VC3. Inside it, you can place your condition check and return false in case the segue should be stopped. Otherwise, return true to make the segue happen. Here is a sample code for your case.

    override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
    
        if identifier == "submitUnwindSegue"{
            if string.toInt() < minimum {
                //fire an alert controller about the error
                return false
            }
        }
    
        //Continue with the segue
        return true  
    
    0 讨论(0)
  • 2021-01-06 10:36

    To achieve this, connect Controller of VC3 to its own exit and select the unwind action.

    Give this exit-segue a segue.identifier "YOUR EXIT TEXT"

    Still in VC3, create an IBAction for the "Accept" button.

    @IBAction func accept(sender: AnyObject) {
        if //Condition X is true
            {performSegueWithIdentifier("YOUR EXIT TEXT", sender: self)}
        else {
            //Do this
            }
    
    0 讨论(0)
提交回复
热议问题