开发者

Multi-level navigation controller on left-hand side of UISplitView with a small twist

I'm trying to make something similar to (but not exactly like) the email app found on the iPad.

Specifically, I'd like to create a tab-based app, but each tab would present the user with a different UISplitView.

Each UISplitView contains a Master and a Detail view (obviously).

In each UISplitView, I would like the Master to be a multi-level navigational controller where new UIViewControllers are pushed onto (or popped off of) the stack. This type of navigation within the UISplitView is where the application is similar to the native email app.

To the best of my knowledge, the only place that has described a decent "splitviewcontroller inside of a uitabbarcontroller" is here: UISplitViewController in a TabBar ( UITabBarController )? and I've tried to follow the accepted answer.

The accepted solution seems to work for me (i.e., I get a tab-bar controller that allows me to switch between different UISplitViews).

The problem is that I don't know how to make the left-hand side of the UISplitView to be a multi-level navigation controller.

Here is the code I used within my app delegate to create the initial "split view 'inside' of a tab bar controller" (it's pretty much as suggested in the aforementioned link).

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

    NSMutableArray *tabArray = [NSMutableArray array];

    NSMutableArray *array = [NSMutableArray array];
    UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
    MainViewController *viewCont = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
    [array addObject:viewCont];
    [viewCont release];
    viewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
    [array addObject:viewCont];
    [viewCont release];
    [splitViewController setViewControllers:array];
    [tabArray addObject:splitViewController];
    [splitViewController release];



    array = [NSMutableArray array];
    splitViewController = [[UISplitViewController alloc] init];
    viewCont = [[Master2 alloc] initWithNibName:@"Master2" bundle:nil];
    [array addObject:viewCont];
    [viewCont release];
    viewCont = [[Slave2 alloc] initWithNibName:@"Slave2" bundle:nil];
    [array addObject:viewCont];
    [viewCont release];
    [splitViewController setViewControllers:array];
    [tab开发者_如何学CArray addObject:splitViewController];
    [splitViewController release];

        // Add the tab bar controller's current view as a subview of the window
    [tabBarController setViewControllers:tabArray];

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

    return YES;
}

the class MainViewController is a UIViewController that contains the following method:

- (IBAction)push_me:(id)sender {
    M2 *m2 = [[[M2 alloc] initWithNibName:@"M2" bundle:nil] autorelease];
    [self.navigationController pushViewController:m2 animated:YES];
}

this method is attached (via interface builder) to a UIButton found within MainViewController.xib Obviously, the method above (push_me) is supposed to create a second UIViewController (called m2) and push m2 into view on the left side of the split-view when the UIButton is pressed. And yet it does nothing when the button is pressed (even though I can tell that the method is called).

Thoughts on where I'm going wrong?

TIA!


Create a Subclass of your (multi-level) Master Navigation Controller and override the following method:

- separateSecondaryViewControllerForSplitViewController:

Inside the overriden method perform the super class method and check if you want to split the returned view controller from it, if not then let remerge it back by calling the collapse method:

- collapseSecondaryViewController:forSplitViewController:

Template example in Swift:

import UIKit

class MasterNavigationController: UINavigationController {

    override func separateSecondaryViewControllerForSplitViewController(splitViewController: UISplitViewController) -> UIViewController? {

        // Separate a view controller from master navigation controller
        if let secondaryViewController = super.separateSecondaryViewControllerForSplitViewController(splitViewController) {

            if /* Check if secondaryViewController is your Detail View Controller (you can check for its class or restorationIdentifier for example) */ {

                return secondaryViewController

            } else {

                // Remerges the separated view controller back to the master navigation controller
                super.collapseSecondaryViewController(secondaryViewController, forSplitViewController: splitViewController)
            }
        }
        return nil
    }
}


Are you sure that MainViewController is a subclass of UINavigationController?

If you want to be able to push/pop controllers then the mainViewController should be a navigationController (or subclass) and then you would push controllers (e.g. TableViewControllers) onto that. You can see this structure in the default splitView project (open up IB and inspect the views).

Here is a decent tutorial on UISplitViewController: http://mobiforge.com/developing/story/developing-split-view-based-apps-ipad

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜