views:

339

answers:

4

Hi i have a splitViewController

mapViewController = [[MapViewController alloc] initWithManagedObjectContext:managedObjectContext startingRegion:startingRegion];

    distanceViewController = [[DistanceTableViewController alloc] initWithManagedObjectContext:managedObjectContext];
    distanceViewController.mapViewController = mapViewController;
    setupViewController = [[SetupTableViewController alloc] initWithStyle:UITableViewStyleGrouped map:mapViewController.map];   
    setupViewController.positionSwitch.on = savePosition;

    SearchTableViewController *searchViewController = [[SearchTableViewController alloc]  initWithStyle:UITableViewStylePlain managedObjectContext:managedObjectContext];   
    searchViewController.mapViewController = mapViewController;

    tabBarController = [[UITabBarController alloc] init];

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        UINavigationController *mapNavigationController = [[[UINavigationController alloc] initWithRootViewController:mapViewController] autorelease];
        UINavigationController *searchNavigationController = [[[UINavigationController alloc] initWithRootViewController:searchViewController] autorelease];
        UINavigationController *distanceNavigationController = [[[UINavigationController alloc] initWithRootViewController:distanceViewController] autorelease];
        UINavigationController *setupNavigationController = [[[UINavigationController alloc] initWithRootViewController:setupViewController] autorelease];

        UISplitViewController* splitVC = [[UISplitViewController alloc] init];
        splitVC.viewControllers = [NSArray arrayWithObjects:searchNavigationController, mapNavigationController, nil];
        splitVC.title = @"iMetano";
        splitVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Mappa" image:[UIImage imageNamed:@"mapIcon2.png"] tag:0] autorelease];

        NSArray *viewControllersArray = [NSArray arrayWithObjects: splitVC,setupNavigationController,nil];
        [splitVC release];

        tabBarController.viewControllers = viewControllersArray;
    }

When i startup my app in portrait, all works fine.

When i startup my app in landscape this is the result

alt text

  1. I see only the view of the first viewController SearchTableViewController with some pixel between the UINavigationController and the status bar
  2. When i rotate in portrait and after i return in landscape i see both viewController's view, but the second have some pixel between the statusBar and the UINavigationControllor

I can't understand why.

A: 

I have the same problem.

Cristian
A: 

After looking at my code and IB time after time. This is the best that I could come up with. Not sure if is the best one but it works for me. Im loading a default detail view controller. If I load the controller directly in the viewDidLoad then the problem occur. If I load it from the selector the problem goes away. I hope this helps. I have this code in the RootViewController.

    - (void)viewDidLoad {
        [super viewDidLoad];
        [self performSelector:@selector(loadController) withObject:nil afterDelay:0];
    }

    -(void)loadController{
    UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
    WebViewController *newDetailViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
    [newDetailViewController setTitle:@"Home"];
    NewNavController <SubstitutableDetailViewController>*navController = [[NewNavController alloc] initWithRootViewController:newDetailViewController];

    detailViewController = navController;

    NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
    splitViewController.viewControllers = viewControllers;


}
Cristian
Tnx, but this don't works for me.
Luca Bartoletti
A: 

I had this exact same problem when attempting the combination of tab bar, split view and navigation controllers. I noticed that the alignment gap is only present when the application first fires up and the first tab is auto-selected because it's the first tab in the tab bar controller's array of view controllers. After switching tabs and then coming back to the one with the misaligned nav controller in a split view, there was no alignment problem present. So, to replicate this behavior and get rid of the misalignment when the screen is first rendered I added:

[tabBarController setSelectedViewController:splitVC];

right after setting the view controller array on the tab bar controller. Works like a champ now.

ScottS
A: 

apple says not to put a split view controller inside something else, like a tab bar controller