I have a tab bar controller on my main window. Each tab is associated with a different view controller and when you click on a tab it sets a different view controller as the selected controller.
My problem is how to pass objects to the view controller e.g. managed context. Any ideas?
- (IBAction)mainMenuButtonTapped:(id)sender {
if (![myTabBarController.view window]) {
[self.window addSubview:myTabBarController.view];
}
UIViewController *selectedViewController = [myTabBarController.viewControllers objectAtIndex:[sender tag]]; //I wanted to pass the self.managedObjectContext to the view controller here, I have tried casting but that doesn't work because some of the vc's are navigation controllers. I have tried using outlets etc.
[myTabBarController setSelectedViewController:selectedViewController];
}
Simply get the
managedObjectContextfrom your app delegate inviewDidLoadof each view controller.