Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在Swift中使用警报视图展开segue?_Iphone_Swift_Uialertview_Unwind Segue - Fatal编程技术网

Iphone 如何在Swift中使用警报视图展开segue?

Iphone 如何在Swift中使用警报视图展开segue?,iphone,swift,uialertview,unwind-segue,Iphone,Swift,Uialertview,Unwind Segue,我有几个视图控制器。如果警报视图得到确认,我需要返回到第一个视图控制器。这就是我在没有放松阶段的情况下的做法: @IBAction func unwindToDelete ( segue: UIStoryboardSegue ) { let alertView = UIAlertController(title: "Delete?", message: "Are you sure you wante to delete?", preferredStyle: .ActionSheet)

我有几个视图控制器。如果警报视图得到确认,我需要返回到第一个视图控制器。这就是我在没有放松阶段的情况下的做法:

@IBAction func unwindToDelete ( segue: UIStoryboardSegue ) {

    let alertView = UIAlertController(title: "Delete?", message: "Are you sure you wante to delete?", preferredStyle: .ActionSheet)

    let deleteAction = UIAlertAction (title: "Delete", style: .Destructive ) { alertAction in

        self.deleteChoice = true
    }

    let cancelAction = UIAlertAction (title: "Cancel", style: .Cancel ) {  alertAction in

    }

    alertView.addAction(deleteAction)
    alertView.addAction(cancelAction)

    self.presentViewController(alertView, animated: true, completion: nil)

}
但是如果我这样做,在这段代码中,它会因为最后一行代码而崩溃

这就是错误:

2015-04-30 14:59:45.605 PhotosCollection[4624:182995] 
popToViewController:transition: called on <UINavigationController 0x7a67aeb0> 
while an existing transition or presentation is occurring; the navigation 
stack  will not be updated. 
2015-04-3014:59:45.605照片收集[4624:182995]
popToViewController:转换:已调用
当现有转换或呈现正在发生时;导航
堆栈将不会被更新。
如何在能够解开segue的同时完成警报视图


谢谢你

你在放松发生后发出警报。如果用户选择取消删除,您希望能够完全不执行展开。我建议如下:

  • 与其将展开序列连接到删除按钮,不如将其连接到视图控制器顶部的视图控制器图标,以便可以编程方式调用展开。此答案向您展示了如何做到这一点: . 为展开序列指定一个标识符,例如
    “doUnwind”
  • 在“删除”按钮的
    @IBAction
    中,显示警告,询问用户是否确实要删除

  • 在delete按钮的处理程序中,以编程方式调用unwind segue

        @IBAction func deleteButton (button: UIButton) {
    
            let alertView = UIAlertController(title: "Delete?", message: "Are you sure you wante to delete?", preferredStyle: .ActionSheet)
    
            let deleteAction = UIAlertAction (title: "Delete", style: .Destructive ) { alertAction in
    
                 self.performSegueWithIdentifier("doUnwind", sender: self)
            }
    
            let cancelAction = UIAlertAction (title: "Cancel", style: .Cancel ) {  alertAction in
    
            }
    
            alertView.addAction(deleteAction)
            alertView.addAction(cancelAction)
    
            self.presentViewController(alertView, animated: true, completion: nil)
    
        }
    

  • 看起来您在播放动画时正在调用unwind segue。。。在设置一定的延迟后尝试将其释放…您是否尝试在按钮上添加处理程序,以便在截获“删除”事件后再释放?