繁体   English   中英

如何在选项卡栏项目上轻按以方式显示View Controller

[英]How to modally present a View Controller on tap of tab bar item

我在情节提要中创建了一个带有3个栏项目的选项卡栏视图控制器。

现在点击选项卡栏项,我想展示一个ViewController,它通过导航控制器连接到选项卡栏项。

由于尚未创建任何选项卡栏对象,因此如何以编程方式实现此目的。

(或)是否有一种方法可以捕获选项卡栏项的选择(在情节提要中创建)

谢谢...

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

将其添加到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
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM