UISplitViewController Getting Detail VC Only in Portrait View

136 Views Asked by At

I have recently removed the tab bar from my app in favor of a "slide out" styled menu which I have written myself. It appears to be working perfectly, except that the one split-view controller I use in the app does not work correctly on the iPad in portrait orientation (landscape is just fine). The problem I'm seeing is the detail VC ONLY is loaded into the portrait view, where both VCs load correctly in landscape view. This is on iOS7.

So, here is the code I'm using. This code has been moved from the AppDelegate (previously) to the root VC. There were some changes but relatively minor. It did work fine with the tab bar, but using this new slide out menu (i.e., a table view) I have this one problem. I'm only including the portions of the code that I think would be relevant.

AdminMasterViewController *adminMasterVC = [[AdminMasterViewController alloc] init];
UINavigationController *adminMasterNav = [[UINavigationController alloc] init];
adminMasterNav.viewControllers = [NSArray arrayWithObjects:adminMasterVC, nil];
adminMasterNav.view.frame = CGRectMake(0,0,[Utility screenWidth],[Utility screenHeight]);

AdminDetailViewController *adminDetailVC = [[AdminDetailViewController alloc] init];
UINavigationController *adminDetailNav = [[UINavigationController alloc] init];
adminDetailNav.viewControllers = [NSArray arrayWithObjects:adminDetailVC, nil];
adminDetailNav.view.frame = CGRectMake(0,0,[Utility screenWidth],[Utility screenHeight]);

UISplitViewController *adminSplitVC = [[UISplitViewController alloc] init];
adminSplitVC.viewControllers = [NSArray arrayWithObjects: adminMasterNav, adminDetailNav, nil];
adminSplitVC.delegate = self;
adminSplitVC.title = @"Admin";
adminSplitVC.view.frame = CGRectMake(0,0,[Utility screenWidth],[Utility screenHeight]);

vcArray = [NSArray arrayWithObjects:homeVC, adminSplitVC, expressiveNav, receptiveNav, typerNav, nil];

(The last line builds the array of all the VCs in the project; the code which creates these VCs has been omitted).

After the VC has been selected it is presented as a child VC as follows:

UIViewController *vc;
if ([selected isEqualToString:@"Home"])
{
    vc = [vcArray objectAtIndex:VCHome];
}
else if ([selected isEqualToString:@"Administrator"])
{
    vc = [vcArray objectAtIndex:VCAdmin];
}

... (others listed here)

[self.view addSubview:vc.view];
[self addChildViewController:vc];
[vc didMoveToParentViewController:self];

From what I have read there may be some issue with NOT using the tab bar, but the articles are confusing because a lot of them are dated. I will appreciate any input or suggestions on this problem as I've read everything I can find and don't really know where to go from here. TIA.

1

There are 1 best solutions below

0
On

After a couple of days of reading and trying different things, an hours after posting the question I solved this. Just in case anyone else hits this same problem, here's the solution:

I subclassed the UISplitViewController and made it its own delegate.

Then, this delegate method solved it:

- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
    return NO;
}