-3

我不知道如何初始化包含标签栏的视图控制器,并且标签栏中有 2 个视图控制器?

我有一个 current_view_controller、一个 OrderPanel、一个 firstViewController 和一个 SecondViewController。

firstViewController 和 SecondViewController 是 OrderPanel 中的选项卡。如何正确初始化和调用 current_view_controller 中的 OrderPanel?

这是将选项卡设置为视图控制器的类 OrderPanel

  #import "OrderPanel.h"

  #import "OrderPanelFirstViewController.h"

  #import "OrderPanelSecondViewController.h"

  @implementation OrderPanel

  @synthesize window = _window;
  @synthesize tabBarController = _tabBarController;

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:            (NSDictionary *)launchOptions
  {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    viewController1 = [[OrderPanelFirstViewController alloc]       initWithNibName:@"OrderPanelFirstViewController_iPhone" bundle:nil];
    viewController2 = [[OrderPanelSecondViewController alloc]       initWithNibName:@"OrderPanelSecondViewController_iPhone" bundle:nil];
} else {
    viewController1 = [[OrderPanelFirstViewController alloc] initWithNibName:@"OrderPanelFirstViewController_iPad" bundle:nil];
    viewController2 = [[OrderPanelSecondViewController alloc] initWithNibName:@"OrderPanelSecondViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

那么如何在我当前的视图控制器中调用 orderPanel 呢?

 - (IBAction)T1pressed:(id)sender {
         // how do i call order panel?

}
4

1 回答 1

1

尝试这个:

self.tabBarController = [[UITabBarController alloc] init];

UIViewController *viewController1 = [[firstViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1 ,viewController2, nil];

[self.view addSubview:tabBarController.view];
于 2013-01-25T10:43:57.237 回答