我有一个带有多个选项卡的选项卡栏应用程序,这一切都没有问题。每个选项卡都会转到一个新页面并打开一个新 View 。
我想做的是添加一个选项卡,它不会打开新页面或新 View Controller ,但会在当前页面顶部弹出一个选择器 View 。从该选择器中选择一个选项将跳转到新 View 。
所以在标签中:
第 1 页/第 2 页/第 3 页/选择器
前 3 个选项卡中的任何一个都会立即跳转到新页面。第 4 个选项卡打开带有第 4 页/第 5 页等选项的选择器,选择其中一个然后转到该页面。
如果您取消选择器 View ,该应用会停留在当前页面/选项卡上。
这在技术上是否可行,Apple 准则是否允许此类行为?
最佳答案
您需要子类化 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;
}
这将阻止选项卡栏实际显示一个新的 View Controller ,相反,您可以对其进行编码以执行任何您想要的操作。请注意,您仍然需要为该选项卡使用某种占位符 View Controller ,即使您永远不会查看它。它只需要保留一个位置,以便标签栏 Controller 知道它需要一个标签。
关于ios - ios中的选项卡栏打开一个选择器,而不是一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16487657/