简体   繁体   中英

Unwind Segue not being performed after shouldPerformSegueWithIdentifier UIAlertController

I have an unwind segue from a UIViewController named DetailViewController to MainViewController defined as (within MainViewController ):

@IBAction func deleteItemUnwind(sender: UIStoryboardSegue)
{
    let sourceViewController = sender.sourceViewController
}

In the DetailView, I have the button that should perform the segue connected to the scene exit with the name deleteItemUnwindSegue , and in DetailViewController I have the prepareForSegue change the value of some variables. This works fine. The problem is, I have the following code in DetailViewController

    override func shouldPerformSegueWithIdentifier(identifier: String!, sender: AnyObject!) -> Bool {

    if (identifier == "deleteItemUnwindSegue") {

        let deleteItemAlert: UIAlertController = UIAlertController(title: "Delete item", message: "Are you sure you want to delete this item?", preferredStyle: .ActionSheet)

        let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
            return false
        }
        deleteItemAlert.addAction(cancelAction)

        let deleteItemAction: UIAlertAction = UIAlertAction(title: "Yes", style: .Destructive) { action -> Void in
            return true
        }
        deleteItemAlert.addAction(deleteChoreAction)

        self.presentViewController(deleteItemAlert, animated: true) {

        }
    }
    return true
}

And while the prepareForSegue code works, the Unwind segue itself is not triggered to dismiss the view. Any ideas?

I figured out that(after reading up on UIAlertController ) the moment after the alert is displayed, the code after it is carried out, so it wold automatically give false every time. I was able to bypass this by creating a generic First Responder to Exit unwind segue, and have the button item trigger the segue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM