我可以在视图控制器中使用tabbar控制器而不是委托类吗?

时间:2012-09-24 10:03:52

标签: iphone uitabbarcontroller uitabbar

我在委托类中使用UINavigation控制器。在第三个视图类上导航两个视图类之后,我需要一个tabbar控制器,它可以控制另外三个ViewControllers,并且不应该在前两个视图控制器上看到标签栏。我怎么能这样做?

- (void)viewDidLoad
{

    [super viewDidLoad];

    self.title =@"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];

}

3 个答案:

答案 0 :(得分:1)

按照我的回答...你可以在你想要的时候添加和删除tabBar link

答案 1 :(得分: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];

答案 2 :(得分:0)

理想情况下,TabBarcontroller应该是应用程序的起始情况。但在极少数情况下,您希望在视图控制器中显示它..

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

    [self presentModalViewController:tabBarController animated:NO];