UISplitViewController in a TabBar ( UITabBarController )?

前端 未结 9 869
长发绾君心
长发绾君心 2020-11-30 19:35

I am in kind of situation that I need to start with a tab based application and in that I need a split view for one or more tabs. But it seems that split view controller obj

9条回答
  •  被撕碎了的回忆
    2020-11-30 20:06

    Using the interface builder, create a split view controller and a tab bar controller and link them to your outlets:

    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    @property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
    

    In your app delegate didFinishLaunchingWithOption, assign your split view controller to the tab bar controller:

    splitViewController.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Title" image:nil tag:0] autorelease];
    NSArray *controllers = [NSArray arrayWithObjects:splitViewController,  /* other controllers go here */ nil];
    tabBarController.viewControllers = controllers;
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];
    

    This will create a tab bar controller (with only 1 tab in this case), which is displayed correctly in all orientations.

提交回复
热议问题