开发者

iOS: Hide rootViewController of SplitView in TabBar app

开发者 https://www.devze.com 2023-03-25 02:14 出处:网络
I have a TabBar iPad app with a Split Controller in first tab. I follow this instructions to make it:

I have a TabBar iPad app with a Split Controller in first tab. I follow this instructions to make it:

http://www.iphonedevsdk.com/forum/iphone-sdk-development/62217-simplest-way-make-split-controller-tab-bar-controller.html

Now my goal is to hide the root view controller of the split controller. I found a method to accomplish this:

http://vimeo.com/13054813

But that doesn't works for me, because it only works assuming the split controller is in the MainWindow.xib. But with the previous method, the split controller is added programatically.

Can someone help me to get my goal? Any idea would be appreciate开发者_JS百科d.

Thanks in advance!


Here are the code:

http://dl.dropbox.com/u/27695108/MariCruz.zip

I hope you can help me.

Thanks!


You have a couple of problems with your project.

1 First one is that you are using a UITabBarController, that is why the code you found to hide the root view controller does not work.

  1. Second one lays with your implementation of makeSplitViewController, where you are initializing twice your splitViewController, rootViewController, and detailViewController.

So, you have to fix point 2, so that you can correctly manage all of those controllers and then you should modify toggleSplitView so that you take into account the fact that you are using a UITabBarController. For example, replace the first few lines of that method with the following ones:

- (void)toggleSplitView {

    NSArray *controllers = _tabBarController.viewControllers;
    UIViewController* controller = [controllers objectAtIndex:1];

    if (controller.view == splitViewController.view) {

        [splitViewController.view removeFromSuperview];

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

        splitViewController.view = detailViewController.view;

} else {
       ....

As you say, I am no accessing _window to check if the UISplit is there, because that view is not under _window, rather it is in the tab bar. The other branch of the if also needs to be rewritten according to the same criteria, but I will leave it for you.

The above code will work only with your second tab (the one corresponding to index 1); indeed, since you are overwriting splitViewController in makeSplitViewController, I can only use the element at index 1 in the tab bar without making further changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消