您将需要继承 UITabBarController,并实现此方法:
- (BOOL)tabBarController:(UITabBarController *)tbController shouldSelectViewController:(UIViewController *)viewController
{
NSInteger tabIndex = [[tbController viewControllers] indexOfObject:viewController];
//Check to see if the selected index is the one you want to do something else, in this example, it's the second tab, so index is 1
if(tabIndex == 1)
{
//Write the code you need to pop up the picker here.
return false;
}
return true;
}
这将阻止选项卡栏实际显示新的视图控制器,而是您可以对其进行编码以执行您想要的任何操作。请注意,您仍然必须为该选项卡设置某种占位符视图控制器,即使您永远不会查看它。它只需要保留一个位置,以便标签栏控制器知道它需要有一个标签。