2013-04-24 63 views
0

我有一個由標籤欄製作的x-code項目。在AppDelegate.m創建三個按鈕爲每個視圖:

在標籤欄項目中添加視圖 - xcode

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease]; 
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease]; 
UIViewController *viewController3=[[[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil]autorelease]; 
self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3]; 
self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 
return YES; 

當我第一個觀點我想創建一個按鈕,調用了另一個觀點:

-(IBAction)btnPush{ 
[[self navigationController] pushViewController:newView animated:YES]; 
} 

但是當新的觀點來它覆蓋了botton上的標籤欄。我該如何解決這個問題?

回答

1

而是在UITabBarController添加UIViewController的添加UINavigationController如下

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

現在您的ViewController添加到NavigationController

UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1]; 
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:viewController2]; 
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:viewController3]; 

self.tabBarController.viewControllers = @[navController1, navController2,navController3]; 

它將TabBarController添加導航控制器

+0

有辦法做到沒有導航控制器的相同的東西? – gabboSonc 2013-04-24 08:28:33

+0

我不知道有沒有,我不確定。但很可能沒有辦法。 – 2013-04-24 08:59:01

+0

好的謝謝。順便說一下你的解決方案運行良好。 – gabboSonc 2013-04-24 09:34:06

相關問題