Reputation: 553
Parent
View Controller
_________________
| |
| |
| | Navigation Cont.
|_________________| _________________
| | | |
| | | |
| Container View | --> | | --> Child View Controllers
| | | |
|_________________| |_________________|
My app has a navigation structure composed by a parent view controller and a container that contains a navigation controller (and its child view controllers). The problems is that during the initialisation of these child View Controllers I want to pass some values provided by the Parent View controller. Unfortunately the method prepareForSegue
used in the parent only detects the container segue but its not called when the child view controllers are changing.
How could this problem be addressed? I'm using Swift but I also understand Objective-C.
Upvotes: 4
Views: 2622
Reputation: 553
Well, at the end it took time... but I finally got it.
It's simple: the child will talk with the parent over self.parentview.parentview
. A couple of delegates and it's done.
Upvotes: 1
Reputation: 27438
You can use prepareforsegue
like,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
{
// Get reference to the destination view controller
YourViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object];
}
}
you can do this from container viewcontroller
NSArray *viewControllers = self.navigationController.viewControllers;
UIViewController *rootViewController = (UIViewController *)[viewControllers objectAtIndex:viewControllers.count - 2]; //index of your root viewcontroller
and refer this link for pass data to `containerview's VC'
Upvotes: 0