Apple says about unwind(for:towards:) method (which called when an unwind segue transitions to a new view controller):
During the execution of an unwind segue, UIKit calls this method on any view controllers in the unwind path to give them an opportunity to reconfigure themselves.
ok. I tried to check this fact. in the example there are 4 view controllers each was pushed. So on the outermost view controller i touched unwind button (@ibaction unwind method was implemented in the root view controller (pink)). Each child is ViewController: UIViewController class. And navigation controller is custon NavigationControlllerClass with unwind(for:towrds) and dismiss methods overrode to print the have been called.
But
So. According to apple words unwind(for:towards:) have to be called 4 times on ViewController: UIViewController class, and 1 times on CustomNavitaionController class. But it has been called only once on Viewcontroller class and only once on CustomNavigationController class. Why so??? Apple says on any...(((
class ViewController : UIViewController {
@IBAction func doUnwind(_ sender:UIStoryboardSegue) {
}
override func allowedChildrenForUnwinding(from source: UIStoryboardUnwindSegueSource) -> [UIViewController] {
let result = super.allowedChildrenForUnwinding(from: source)
print("\(self) \(#function) \(result)")
return result
}
override func unwind(for unwindSegue: UIStoryboardSegue, towards subsequentVC: UIViewController) {
print("\(self) \(subsequentVC)")
super.unwind(for: unwindSegue, towards: subsequentVC)
}
override func canPerformUnwindSegueAction(_ action: Selector, from fromViewController: UIViewController, sender: Any?) -> Bool {
var result = super.canPerformUnwindSegueAction(action, from: fromViewController, sender: sender)
return result
}
override func dismiss(animated: Bool, completion: (() -> Void)?) {
print("\(self) \(#function)")
super.dismiss(animated:animated, completion: completion)
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
let result = super.shouldPerformSegue(withIdentifier: identifier, sender: sender)
if identifier == "unwind" {
print("\(self) \(#function) \(result)")
}
return result
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "unwind" {
print("\(self) \(#function)")
}
}
}
class MyNavController : UINavigationController {
override func allowedChildrenForUnwinding(from source: UIStoryboardUnwindSegueSource) -> [UIViewController] {
let result = super.allowedChildrenForUnwinding(from: source)
print("\(type(of:self)) \(#function) \(result)")
return result
}
override func unwind(for unwindSegue: UIStoryboardSegue, towards subsequentVC: UIViewController) {
print("\(type(of:self)) \(#function) \(subsequentVC)")
super.unwind(for: unwindSegue, towards: subsequentVC)
}
override func canPerformUnwindSegueAction(_ action: Selector, from fromViewController: UIViewController, sender: Any?) -> Bool {
let result = super.canPerformUnwindSegueAction(action, from: fromViewController, sender: sender)
print("\(type(of:self)) \(#function) \(action) \(result)")
return result
}
override func dismiss(animated: Bool, completion: (() -> Void)?) {
print("\(type(of:self)) \(#function)")
super.dismiss(animated:animated, completion: completion)
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
let result = super.shouldPerformSegue(withIdentifier: identifier, sender: sender)
if identifier == "unwind" {
print("\(type(of:self)) \(#function) \(result)")
}
return result
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "unwind" {
print("\(type(of:self)) \(#function)")
}
}
override func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]? {
print("\(type(of:self)) \(#function) \(viewController)")
return super.popToViewController(viewController, animated:animated)
}
}