0

I have a problem I can't figure out, I have made an application which uses UIsplitview inside a tab bar. I have been implementing the different tabs however now when I am working on the first tab - the UIsplitview is not aligned in landscape mode. Do you guys have any suggestions - if I start it in portrait and go to landscape, then there's no problem at all.

enter image description here

Update: I dont do any init with frames anywhere, and I have checked the sizes etc. in IB. The following shows how I add the uisplitview controller in the app delegate. It has been done this way because I wanted a splitview in a tabbar controller. When i have added the spilview I just set the master and detail view in IB. A bit of mystery.

if (index == 2) {

        detailViewController = [[DetailUserCreatorViewController alloc] initWithNibName:@"DetailUserCreatorView" bundle:nil];

        userContent=[[UserContentForPopViewController alloc]init];

        userContent.userDetails=detailViewController;

        detailViewController.delegate=userContent;

        //rootViewController.navigationItem.title = @"List";
        UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:userContent] autorelease];

        splitViewController = [[UISplitViewController alloc] init];
        splitViewController.tabBarItem = controller.tabBarItem;
        splitViewController.viewControllers = [NSArray arrayWithObjects:nav, detailViewController, nil];

        splitViewController.delegate = detailViewController;

        [controllers replaceObjectAtIndex:index withObject:splitViewController];
    }

Update: I tried to set the selected tab in application didfinishlaunch in the app delegate - self.tabBarController.selectedIndex = 0; and this made the tab start at the correct placement. However it does not seem to be a proper solution.

Bjarke
  • 1,283
  • 11
  • 36
  • posting some code might help...also, it seems the view is displaced downwards by 20 points(height of status bar). – tipycalFlow Sep 01 '11 at 17:13
  • It seems that way - I have added how I set up the splitview controller is there is other part of the code which might indicate the problem please reply and I shall post that too – Bjarke Sep 02 '11 at 06:44
  • Have you used a nib for `UserContentForPopViewController`? – tipycalFlow Sep 02 '11 at 06:51
  • Yes I have have - maybe I should try to load it with the nib file – Bjarke Sep 02 '11 at 06:59
  • It did not do anything, however I tried to set the selected tab in application didfinishlaunch in the app delegate - self.tabBarController.selectedIndex = 0; and this made the tab start at the correct placement. However it does not seem to be a proper solution. – Bjarke Sep 02 '11 at 07:02

1 Answers1

0

Some pointers...splitViewController needs to be added as a subview of window:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

[window addSubview:splitViewController.view];
[window makeKeyAndVisible];

return YES;
}

The following code is incorrect. You should not assign a viewController to a delegate.

splitViewController.delegate = detailViewController;

You will also not require this line of code:

[controllers replaceObjectAtIndex:index withObject:splitViewController];

The following line handles that part of assigning delegates.

splitViewController.viewControllers = [NSArray arrayWithObjects:nav, detailViewController, nil];

Also, if you can upload your code, I'll try to correct it and post back the reason and corrected code...

tipycalFlow
  • 7,594
  • 4
  • 34
  • 45
  • Hey, Thank you for your suggestions. You were right about the delegation. However because I have mutiple uisplitviews in different tabs it seems that I have to add them this way. Maybe this was not clear with the initial explanation. Again thank you for replying. – Bjarke Sep 02 '11 at 07:39
  • Wait...Do you "have mutiple uisplitviews in different tabs" or the other way around? It should be the other way around. See this http://stackoverflow.com/questions/7159352/uitabbarcontroller-in-uisplitviewcontroller/7160544#comment-8596477 – tipycalFlow Sep 02 '11 at 07:42
  • sorry for that I have one uisplitview in each tab:) – Bjarke Sep 02 '11 at 09:12
  • so there's your problem...that's why there was a downshift of 20 points.I suggest you go through [this documentation](http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewControllerDelegate_protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40009454) and the [splitView](http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewController_class/Reference/Reference.html) docs – tipycalFlow Sep 02 '11 at 09:31