My App navigation is like below:
NavigationController ---> RootViewController --(Show Segue)-> SomeViewController --(Show Segue)-> ParentViewController (With ContainerView)
So, ParentViewController has a container view. This container view is populated programmatically, at runtime, depending upon user selection. So, basically the view hierarchy is like this:
ParentViewController (With ContainerView) ---(Embed Segue) --> ContainerViewController --(Custom Segue, for deciding which child to show at runtime) ---> FirstChildViewController/SecondChildViewController
Now, I display a modal view when a button is tapped in SecondChildViewController. Everything is fine, till this point.
But, now I want to update data in SecondChildViewController on the dismissal of ModalViewController. I try to do it like this in ModalViewController:
SecondChildViewController *secondChildVC = (SecondChildViewController *)self.presentingViewController;
[self dismissViewControllerAnimated:YES completion: ^{ [secondChildVC updateList]; }];
But, I am getting following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController updateList]: unrecognized selector sent to instance 0x127e451b0'
How can I fix this issue? So, to be specific, how can I get the "real" presentingViewController? I know its a bit weird navigation, and there is too much stacking on views from user experience point of view, but that is the way client wants to implement.
I am not sure if I understood your question correctly. If you have a ViewController A, presenting ViewController B, and if you wish to call a method in A when B is dismissed - you can make A a delegate of B.
Read more about Protocols and Delegates here: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.