2012-11-08 34 views
0

我想創建類似下面的內容。 RootView沒有TabBar,從第二個視圖中應該有TabBar。UITabBarController問題

enter image description here

我所目前做的是,我使用UINavigationController作爲控制器calass

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 


    UIViewController *rootController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 

    navigationController = [[UINavigationController alloc] initWithRootViewController:rootController]; 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [self.window addSubview:navigationController.view]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

但我怎麼能使用UITabBar與tabBarController從SecondViewController?

請給我一個手

回答

0

從故事板中嵌入的TabBar您SecondViewController。選擇您的控制器並轉到編輯器 - >嵌入 - > TabBar控制器!我來自我的手機。如果我有任何失誤,請聯繫我!

-1

創建使用標籤欄控制器和對要隱藏標籤欄使用代碼視圖控制器的viewDidLoad方法的應用:

 [self.tabBarController.tabBar setHidden:YES]; 

而且不要忘記使用取消隱藏標籤欄對於要顯示標籤欄的視圖控制器,將相同的代碼替換爲NO而不是YES。

+0

-1。無需將根視圖控制器更改爲UITabBarController。 – ozz

0

你需要推動你的Tabbar控制器的對象。初始化標籤欄控制器的對象,並將所有其他控制器對象添加到標籤欄控制器的viewcontroller數組中。

在按鈕操作: -

1>初始化標籤欄控制器和假設你的名字及其作爲objTab對象;

2> objTab.viewcontrollers = [NSArray arrayWithObjects:..] --->屬於您的標籤欄控制器的所有視圖控制器的對象。因此需要首先創建所有對象。

3> self.navigationcontroller pushViewController:objTAb

1

創建所述第二視圖中的對象,然後與tabbarcontroller

0

使用在AppDelegate.m和這種類型的方法的推視圖屬性-合成UITabBarController和存儲陣列視圖 - 控制它也應用didFinishLaunchingWithOptions方法只是分配navigationViewController像波紋管一RootViewController的..

RootViewController *masterViewController = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease]; 
    self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease]; 

後然後當你想要的TabBar在那個時候添加到任何視圖這樣調用這個方法波紋管..

[appDelegate addTabBarControllerInwindow]; 

-(void)addTabBarControllerInwindow 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES]; 

    [self.navigationController.view removeFromSuperview]; 
    [self.window addSubview:[tabBarController view]];//tabBarController.view 
    [UIView commitAnimations]; 
} 

我希望這對您有所幫助,並從中得到一些代碼想法..

0

喜歡的東西這應該做(不使用ARC)的伎倆:

//vc1, vc2, vc3 = your view controllers 
NSArray *viewControllersArray = [NSArray arrayWithObjects:vc1,vc2,vc3, nil];  
UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
[tabBarController setViewControllers:viewControllersArray]; 
[self.navigationController pushViewController:tabBarController animated:YES]; 
[tabBarController release]; 

你想要做的是創造的UITabBarController,推動沿導航堆棧。

0

對於示例在appdelegate上寫入loadnewview方法。如下所示,使用buttonPressed方法執行按鈕操作或第一個視圖控制器的任何對象操作,以顯示來自第二個視圖控制器的選項卡欄。 我採取了兩個標籤樣本,所以我寫容量爲2.您最多可以接受5.

-(IBAction)buttonPressed:(id)sender 
{  
    HomeViewController *homeVC=[[HomeViewController alloc]initWithNibName:@"HomeViewController" bundle:nil]; 

    [self.navigationController pushViewController:homeVC animated:YES];   
    [appDelegate loadnewview]; 
}  

-(void)loadnewview 
{  
    if(!self.tabBarController) 
     self.tabBarController = [[UITabBarController alloc] init]; 

    self.tabBarController.delegate=self;  
    NSMutableArray *localcontrollerarray = [[NSMutableArray alloc] initWithCapacity:2];   
    UIViewController *viewController1 = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];   
    UINavigationController *navi1 = [[UINavigationController alloc] initWithRootViewController:viewController1];   
    [localcontrollerarray addObject:navi1];   
    UIViewController *viewController2 = [[ScanViewController alloc] initWithNibName:@"ScanViewController" bundle:nil];  
    UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:viewController2];   
    [localcontrollerarray addObject:navi2];   
    self.tabBarController.viewControllers = localcontrollerarray;  
    [self.window addSubview:self.tabBarController.view];  
} 
相關問題