首页 文章

如何在标签栏项目上模拟呈现视图控制器

提问于
浏览
0

我在故事板中创建了一个带有3个条形项的标签栏视图控制器 .

现在点击标签栏项目,我想呈现一个ViewController,它通过导航控制器连接到标签栏项目 .

如何以编程方式实现这一点,因为我还没有创建任何标签栏对象 .

(或)有没有办法捕获标签栏项目选择(在故事板中创建)

谢谢...

2 回答

  • 0

    在viewDidLoad中添加:为每个按钮分配视图控制器:

    self.tabBarController.viewControllers = 
     @[firstViewController,secondViewController,thirdViewController];
    

    以下是检测按钮点击的方法:

    -(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    {
        if (tabBarController.selectedIndex == 0) {
           // present your first view controller
        }
        else if (tabBarController.selectedIndex == 1) {
          // present your second view controller
        }
        else if (tabBarController.selectedIndex == 2) {
          // present your third view controller
        }
    }
    
  • 0

    使用UITabBarControllerDelegate可以获得有关选择了哪个选项卡的通知 .

相关问题