2013-07-02 52 views
0

我想在我的應用程序設置的TabBar,在我的appDelegate我做這個啓動tabbarcontroller:IOS:在secondviewcontroller

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease]; 
    UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease]; 
    [viewController2 viewDidLoad]; 
    UIViewController *viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil] autorelease]; 
    [viewController3 viewDidLoad]; 
    UIViewController *viewController4 = [[[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil] autorelease]; 
    [viewController4 viewDidLoad]; 
    self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
    self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4]; 

    self.viewController = [[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil] autorelease]; 

    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

你可以看到,我想不會立即開始我的應用程序標籤欄,其實我開始我的應用程序與HomeViewController

我HomeViewController裏面我打開viewController1有:

FirstViewController *first = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil]; 
    [self presentViewController:first animated:YES completion:nil]; 
    [first release]; 

但在我firstviewcontroller我沒有看到我的TabBar,爲什麼呢? (我聲明,如果我沒有使用homeviewcontroller,應用程序可以正常工作)

回答

1

您看不到tabbar,因爲在HomeViewController中創建FirstViewController的新實例並以模態方式呈現它。您應該創建並提出內部HomeViewController整個的UITabBarController:

的AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

    self.viewController = [[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil] autorelease]; 

    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

內HomeViewController:

FirstViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease]; 
SecondViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease]; 
ThirdViewController *viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil] autorelease]; 
FourthViewController *viewController4 = [[[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil] autorelease]; 

self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4]; 

[self presentViewController:self.tabBarController animated:YES completion:nil]; 
相關問題