gpt4 book ai didi

iphone - 如何在 Swift 中使用警报 View 解除 segue?

转载 作者:行者123 更新时间:2023-11-28 09:34:46 29 4
gpt4 key购买 nike

我有几个 View Controller 。如果 Alert View 被确认,我需要返回到第一个 View Controller。如果没有 unwind Segue,我会这样做:

@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.

如何在能够解除 segue 的同时完成警报 View 。

谢谢

最佳答案

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

  1. 不要将 unwind segue 连接到您的删除按钮,而是将它连接到 View Controller 顶部的 View Controller 图标,以便您可以以编程方式调用 unwind。这个答案告诉你如何做到这一点: Setting up the unwind segue .为 unwind segue 提供一个标识符,例如 "doUnwind"
  2. 在您的删除按钮的 @IBAction 中,发出警告,询问用户是否真的要删除。

  3. 在删除按钮的处理程序中,以编程方式调用展开转场。

        @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)

    }

关于iphone - 如何在 Swift 中使用警报 View 解除 segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29959592/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com