views:

253

answers:

1

So, my iPad program has a pseudo-split view controller (one that I implemented, not base SDK one), and was working correctly a while ago. It has the basic layout (UINavController for master, content view controller for detail on right), but I have it so the master view doesn't disappear when rotated into portrait view.

Recently, I added in a UITabBarController to contain the entire split view, which has made the navigation bar go wonky, while all the other views are positioned fine. In addition, the navigation bar only gets mispositioned when the program starts up while the iPad is in landscape, or upside-down portrait. If it starts out in portrait, everything is fine.

Example images can be found here: http://profile.imageshack.us/user/Pzychotix

Image where the navigation bar is upwards is when I initially launch the program. Image where the navigation bar is downwards is after I rotate once or more times.

Relevant Code:

RootViewController.m:
- (void)loadView {
navController = [[NavigationBreadcrumbsController_Pad alloc] init];

ABTableViewController_Pad * tableViewController = [[ABTableViewController_Pad alloc] initWithNibName:@"ABTableView"];

master = [[UINavigationController_Pad alloc] initWithRootViewController:tableViewController];
[tableViewController release];

// Dummy blank UIViewcontroller
detail = [[UIViewController alloc] init];
detail.view = [[[UIView alloc] init] autorelease];
[detail.view setBackgroundColor:[UIColor grayColor]];

self.view = [[[UIView alloc] init] autorelease];
self.view.backgroundColor = [UIColor blackColor];
[self positionViews];
[self.view addSubview:navToolbarController.view];
[self.view addSubview:master.view];
[self.view addSubview:detail.view];
}


// Handles the respositioning of view into it's current orientation
-(void)positionViews{

CGFloat tabBarOffset = 0;

if(self.tabBarController){
    tabBarOffset = self.tabBarController.tabBar.frame.size.height;
}

if(self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    self.view.frame = CGRectMake(0, 0, 768, 1004);
    navController.view.frame = CGRectMake(0,0,768,44);
    //adjust master view
    [master.view setFrame:CGRectMake(0, 44, 320, 1024 - 44 - 20 - tabBarOffset)];

    //adjust detail view
    [detail.view setFrame:CGRectMake(321,44, 448, 1024 - 44 - 20 - tabBarOffset)];
}
// Landscape Layout
else{
    self.view.frame = CGRectMake(0, 0, 748, 1024);
    navToolbarController.view.frame = CGRectMake(0,0,1024,44);
    //adjust master view
    [master.view setFrame:CGRectMake(0, 44, 320, 768 - 44 - 20 - tabBarOffset)];

    //adjust detail view
    [detail.view setFrame:CGRectMake(321,44, 1024 - 320, 768 - 44 - 20 - tabBarOffset)];
}

}
A: 

Well I've found a solution, though I'm still scratching my head as to why it's working.

Basically, I called layoutIfNeeded on my UINavigationController, and that fixed everything right up. What I don't understand is why it was working before, or why I would need to call layoutIfNeeded, as I assumed setFrame would automatically deal with laying out any subviews of controllers.

David Liu