I have a SplitViewController based app which calls to others UIViewController for being them displayed by replacement in the detail section...
I send them parameters, info, objects and everything works fine by using segues from MasterViewController
But some of my UIViewControllers interact with other UIViewControllers by using Segues, so, for making them working fine I need to embed them inside a UINavigationController
my question is:
How to add a UINavigationController to my segue.destinationViewController when segue is being executed for:
I thought in a solution: -The parameters issue by creating custom delegates or protocols, in MasterViewController -The UINavigationControllers issue by adding them in design mode in storyboard by embedding my UIViewControllers in them
but I need to set to my destinationViewController the UISplitViewController's delegate for displaying the button that shows the MasterViewController in portrait mode...
if I set that in prepareForSegue method, having the UINavigationControllers Holding my ViewControllers, I will be setting the UISplitViewController's delegate to the UINavigationController instead
thanks in advance for the help
EDIT: this was the way I found to solve it:
First I assigned a IBAction to a Button, if my device is not an iPad it will do the normal segue...
- (IBAction)openExecutives:(id)sender {
if ([[[UIDevice currentDevice]model] hasPrefix:@"iPad"]) {
UsersListVC *rightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UsersListVC"];
[self showSplitViewController:rightViewController];
}
else
[self performSegueWithIdentifier:@"viewSceneExecutives" sender:self];
}
This is the function I developed for creating the SplitView with my custom detail...
-(void)showSplitViewController:(id)rightViewController{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"iPad2" bundle: nil];
UINavigationController *leftNavController;
UINavigationController *rightNavController;
MainMenuVC *leftViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"MainMenuVC"];
leftNavController = [[UINavigationController alloc] initWithRootViewController:leftViewController];
rightNavController = [[UINavigationController alloc] initWithRootViewController:rightViewController];
leftNavController.toolbarHidden = FALSE;
rightNavController.toolbarHidden = FALSE;
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];
splitViewController.delegate = rightViewController;
self.view.window.rootViewController = splitViewController;
}
All I did is redraw the splitViewController from the very beggining by creating a function which requires a parameter (UIViewController)
You should set up the controllers in IB embedded in navigation controllers. When you want to access the content controller from your master view controller you can just use the navigation controller property topViewController to get a reference. So in prepareForSegue:, you can do something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UINavigationController *dest = (UINavigationController *)segue.destinationViewController;
self.detailViewController = (DetailViewController *)dest.topViewController;
self.splitViewController.delegate = self.detailController;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With