tabBarControllers 的问题

Trouble With tabBarControllers

这些是我创建 TabBarController 所采取的步骤。

  1. 创建了 3 个视图控制器,在 Storyboard 中给定它们的 Class 名称并将它们嵌入到 TabBarController 中。 (疑惑:我们是否也必须给 TabBarController 起一个 class 名称?)

  2. 我想实现 tabBarController:shouldSelectViewController: 其委托的方法,但不知道具体在哪里做。 我们还可以使协议符合 tabBarController 本身而不是显式创建委托对象吗?如何?

提前致谢! :)

是的,您已经创建了 UITabBarController 的新子class,并在情节提要中将此 class 设置为 well.and 符合 class 到 UITabBarControllerDelegate。

在viewDidLoad方法中写入

 self.delegate=self;

并实现委托方法

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (tabBarController.selectedIndex == 0) {

    }

    if (tabBarController.selectedIndex == 1) {

    }
    if (tabBarController.selectedIndex == 2) {

    }
    if (tabBarController.selectedIndex == 3) {

    }

}