导航后获取tabbarcontroller

时间:2012-01-27 11:05:38

标签: iphone ios xcode uitabbarcontroller uitabbar

我有一个带有按钮的视图控制器,点击该按钮后tabbarcontroller应该出现。如何以编程方式进行操作。?

我找到的所有教程都会在应用程序启动后立即显示标签栏。但我希望在单击按钮并导航到其他视图后可以看到它。

我编写了导航到新页面的代码,以便新页面应该包含标签栏控制器。

-(IBAction)buttonClicked
{

 ViewController *viewController = [[ViewController alloc]initWithNibName:@"view" bundle:nil];
        [self.navigationController pushViewController:viewController animated:YES];
        [viewController release];
}

2 个答案:

答案 0 :(得分:0)

开始使用“单一空视图”项目 然后只需添加一个新的UITabBarController(在我的脑海中)

UITabBarController *tbc = [[UITabBarController alloc] init] autorelease];
[tbc.view setFrame:self.view.bounds];
[tbc setViewControllers:[NSArray arrayWithObjects: viewController1, viewController2, viewController3, nil]];
[self.view addSubview:tbv.view];

然后你必须在tabBarItem属性的相应viewControllers中设置标题和图标:http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/tabBarItem

答案 1 :(得分:0)

尝试这样的事情:

-(IBAction)buttonClicked
{
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    UIViewController *vc1 = [[UIViewController alloc] initWithNibName:@"VC1" bundle:nil];
    UITabBarItem *tbi1 = [[UITabBarItem alloc] initWithTitle:@"VC1" image:[UIImage imageNamed:@"vc1"] tag:1];
    vc1.tabBarItem = tbi1;
    // more viewControllers here

    tabBarController.viewControllers = [NSArray arrayWithObjects:vc1, vc2, vc3, nil];
    [self.navigationController pushViewController:tabBarController animated:YES];
}