简体   繁体   中英

UISplitview not alligned at the top

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.

在此处输入图片说明

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM