gpt4 book ai didi

ios - 在 unwind segue 停止 segue 后显示警报。如何确保在 unwind segue 完成后显示警报?

转载 作者:搜寻专家 更新时间:2023-10-31 19:38:05 29 4
gpt4 key购买 nike

我有一个从 A View Controller 到 B View Controller 的 unwind segue。

在B中做了一个网络操作,操作完成后,响应会显示在A View Controller 中。

我成功制作了这个结构。但是有一个问题:

当我尝试显示警报时,它显示但停止了 segue。我如何确保在 segue 完成后显示警报。

错误在这里:

2016-04-27 14:39:28.350 PROJECT[9100:128844] Presenting view controllers on detached view controllers is discouraged <PROJECT.FeedTableViewController: 0x7a928c00>.
2016-04-27 14:39:28.359 PROJECT[9100:128844] popToViewController:transition: called on <UINavigationController 0x7c12a800> while an existing transition or presentation is occurring; the navigation stack will not be updated.

A 中的展开处理程序:

@IBAction func unwindToFeed(segue: UIStoryboardSegue) {
jsonArray[rowFromShare!]["ApplicationDataUsers"] = jsonFromShare!
tableView.reloadData()
ShowErrorDialog("Success", message: successMessageFromShare!, buttonTitle: "OK")
}

//Error Dialog
func ShowErrorDialog(title:String, message:String, buttonTitle:String){
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default) { _ in })
self.presentViewController(alert, animated: true){}
}

在 B 中展开触发器:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == "unwindToFeed"{
let feedTable = segue.destinationViewController as! FeedTableViewController
feedTable.rowFromShare = row
feedTable.jsonFromShare = jsonToShare
feedTable.successMessageFromShare = successMessageToShare
}

// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}

A = FeedTableViewControllerB = ShareTableViewController

如何确保在 segue 完成后显示警报?

最佳答案

如您所见,unwindToFeed 方法在展开转场完成之前被调用。

一种方法是在 unwindToFeed 方法中设置一个 bool 值,然后在您知道转场已完成时在 viewDidAppear 中检查此 bool 值。如果设置了 bool 值,那么您可以显示警报:

@IBAction func unwindToFeed(segue: UIStoryboardSegue) {
jsonArray[rowFromShare!]["ApplicationDataUsers"] = jsonFromShare!
tableView.reloadData()
self.unwinding = true
}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if (self.unwinding) {
self.ShowErrorDialog("Success", message: successMessageFromShare!, buttonTitle: "OK")
self.unwinding=false
}

关于ios - 在 unwind segue 停止 segue 后显示警报。如何确保在 unwind segue 完成后显示警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36888812/

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