在shouldPerformSegueWithIdentifier UIAlertController之后,Unwind Segue没有被执行

时间:2015-05-31 17:43:55

标签: ios iphone swift uiviewcontroller uialertcontroller

我有UIViewController名为DetailViewControllerMainViewController的展开segue定义为(MainViewController内):

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

在DetailView中,我有一个按钮,它应该执行连接到场景出口的segue,名称为deleteItemUnwindSegue,而在DetailViewController中我有prepareForSegue更改某些变量的值。这很好用。问题是,我在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
}

虽然prepareForSegue代码有效,但不会触发Unwind segue 本身来关闭视图。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我发现(在阅读UIAlertController之后)显示警报后的那一刻,执行后的代码,因此每次都会自动给出错误。我通过创建通用的First ResponderExit展开segue来绕过这个,并让按钮项触发segue。