According to this link , I wanted to pass some data from a B viewController
to its parent, A viewController
, on back press! here is my code :
in my B viewController
, I've added this code -
extension Bcontroller: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
(viewController as? Acontroller)?.number = numberInB
(viewController as? Acontroller)?.myBoolean = boolInB
}
}
and here is my code in A controller :
override func viewWillAppear(_ animated: Bool) {
if number != -1 {
print(myBoolean)
}
}
when I open B controller, navigationController (willShow)
is called, and when I press back button, viewWillAppear
is called first, and then navigationController(willShow)
in B controller is called! so my data is not set, and number
will be always -1
. how can I set these variable?