我有UIViewController
名为DetailViewController
到MainViewController
的展开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 本身来关闭视图。有什么想法吗?
答案 0 :(得分:0)
我发现(在阅读UIAlertController
之后)显示警报后的那一刻,执行后的代码,因此每次都会自动给出错误。我通过创建通用的First Responder
到Exit
展开segue来绕过这个,并让按钮项触发segue。