2012-09-24 35 views
0

我在委託類中使用了一個UINavigation控制器。在瀏覽第三個視圖類的兩個視圖類後,我需要一個tabbar控制器,它可以控制另外三個ViewControllers,並且不應在前兩個視圖控制器上看到Tabbar。我怎樣才能做到這一點 ?我可以在視圖控制器而不是委託類中使用tabbar控制器嗎?

- (void)viewDidLoad 
{ 

    [super viewDidLoad]; 

    self.title [email protected]"Scan"; 

    tabController =[[UITabBarController alloc]init]; 

    ScanTicketView *scan =[[ScanTicketView alloc]initWithNibName:@"ScanTicketView" bundle:nil]; 

    SearchView *search =[[SearchView alloc]initWithNibName:@"SearchView" bundle:nil]; 

    HistoryView *history =[[HistoryView alloc]initWithNibName:@"HistoryView" bundle:nil]; 

    tabController.viewControllers=[NSArray arrayWithObjects:scan,search,history, nil]; 

    [self presentModalViewController:tabController animated:YES]; 

} 
+0

上面是我用來做到這一點的代碼。 –

回答

0

是的,你可以。看到這個link to an example

在你的第二個視圖控制器要推到你的第三視圖(選項卡控制器)做到這一點

UITabBarController *tabBarController=[[UITabBarController alloc]init]; 
tabBarController.viewControllers=[NSArray arrayWithObjects:firstViewController,secondViewController,thirdViewController, nil]; 
//[self.navigationController pushViewController:tabBarController animated:YES];// this works too but since it seems to be against Apple's Human interface Guidelines you can present the view instead of pushing 
[self presentModalViewController:tabBarController animated:NO]; 
+0

這件事不起作用,它給錯誤:「[__NSCFConstantString parentViewController]:發送到實例0x98c8的無法識別的選擇器」 –

+0

在navigationController中推送Tabbarcontroller違反了[人機界面指南](http://developer.apple.com/library/) ios /#DOCUMENTATION/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html) – AppleDelegate

+0

我覺得這個錯誤與你上面的代碼寫出來的代碼有關,你在某個地方調用了類似[self parentViewController]的東西...檢查它 – Neo

1

按照我的答案...你可以添加,只要你想
刪除的TabBar link

+0

請檢查我的代碼,我錯了。 –

0

理想TabBarcontroller應該是要展示它在一個視圖 - 控制遵循少數情況下,app..but的啓動情況..

UITabBarController *tabBarController=[[UITabBarController alloc]init]; 
    tabBarController.viewControllers=[NSArray arrayWithObjects:firstViewController,secondViewController,thirdViewController, nil]; 

    [self presentModalViewController:tabBarController animated:NO]; 
+0

這是我使用的代碼,控制不會超出「tabController.viewcontroller」行,它在我認爲的infinilte循環中被阻塞。 –

+0

您的這段代碼無法正常工作,請指導我正確使用,如果可以的話。謝謝。 –

相關問題