我不知道如何初始化包含标签栏的视图控制器,标签栏中有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?
}
答案 0 :(得分: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];