I have three main view controllers A, B, C, which are presented in the order by show
segue. All the three view controllers are embedded in their own navigation controller. After dismissing a modal controller D presented on C, I would like to go back to controller A and reload data before it appears.
I referred to the solution from this question to unwind segue and wrote an action in controller A (I use AViewController to represent the class of controller A):
@IBAction func prepareForUnwindSegue(segue: UIStoryboardSegue?) {
if let destController = segue?.destinationViewController as? AViewController {
destController.reload()
}
}
override func canPerformUnwindSegueAction(action: Selector, fromViewController: UIViewController, withSender sender: AnyObject) -> Bool {
return self.respondsToSelector(action)
}
I dragged-exit between controller A and C by the above action, and name the unwind segue unwindToA
. Then in the class of controller C, named CViewcontroller, I call the modal view D in one ActionSheet as follow:
let presentDAction = UIAlertAction(title: "Present D", style: .Default, handler: {(_) -> Void in
let controller: AnyObject? = self.storyboard!.instantiateViewControllerWithIdentifier("DView")
if let c = controller as? DViewController {
let navi = UINavigationController(rootViewController: c)
navi.modalPresentationStyle = UIModalPresentationStyle.FullScreen
// the following block wait and execute after view controller D dismissed
c.refreshAndUnwind = {[weak self](refresh) in
if let weakSelf = self {
if(refresh) {
weakSelf.performSegueWithIdentifier("unwindToA", sender: weakSelf)
}
}
}
}
})
The view controller did successfully unwind along with reloading data. However, it seems that the navigation bar remains still on controller C, and its title disappear. I have tried to drag-exit the navigation controller between A and C instead and modify the unwind segue action call to weakSelf.navidationController!.performSegueWithIdentifier("unwindToA", sender: weakSelf)
, but it doesn't work. Did I do anything wrong on my segue unwinding that cause this problem?