如何在点击选项卡栏项目时以模式方式呈现视图控制器
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
}
}
我在情节提要中创建了一个带有 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
}
}