放松后显示警报segue停止了segue。展开segue完成后如何确保显示警报?

时间:2016-04-27 11:44:54

标签: ios swift segue

我有从A视图控制器到B视图控制器的展开segue。

网络操作在B中完成。操作完成后,响应将显示在A视图控制器中。

我成功地建立了这个结构。但是有一个问题:

当我尝试显示警报时,它显示但停止了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 = FeedTableViewController B = ShareTableViewController

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

1 个答案:

答案 0 :(得分:1)

在unwind segue完成之前调用unwindToFeed方法,如您所见。

一种方法是在unwindToFeed方法中设置一个布尔值,然后在知道segue完成时在viewDidAppear中检查此布尔值。如果设置了布尔值,则可以显示警报:

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