iPhone UITabbar项双击弹出控制器 [英] iPhone UITabbar item double-click pops controllers
问题描述
只是发现了一些东西:如果将Tabbar与NavigationController组合在一起(在其堆栈上有一些视图),然后双击TabBarItem,则无论您是否喜欢,该视图都会弹出到第一个ViewController.
just found out something: If you have a Tabbar combined with a NavigationController (that has some views on it's stack) and you double click the TabBarItem, the view pops to the first ViewController, whether you like it or not.
有没有办法防止这种情况?
Is there a way to prevent this?
推荐答案
您可能不应阻止此行为.这是标准的iPhone UI约定,例如点击状态栏以滚动到滚动视图的顶部.
You probably should not prevent this behavior. It's a standard iPhone UI convention, like tapping the status bar to scroll to the top of a scroll view.
如果您确实想执行此操作,则应实现UITabBarController
委托方法-tabBarController:shouldSelectViewController:
,就像提到的mckeed一样.但是,如果您有五个以上的选项卡,则selectedViewController
可能是更多"部分中的视图控制器,而vc
将是[UITabBarController moreNavigationController]
.这是处理这种情况的实现:
If you really want to do it, you should implement the UITabBarController
delegate method -tabBarController:shouldSelectViewController:
, like mckeed mentioned. If you have more than five tabs, however, the selectedViewController
may be a view controller that is in the "More" section, but vc
will be [UITabBarController moreNavigationController]
. Here's an implementation that handles that case:
- (BOOL)tabBarController:(UITabBarController *)tbc shouldSelectViewController:(UIViewController *)vc {
UIViewController *selected = [tbc selectedViewController];
if ([selected isEqual:vc]) {
return NO;
}
if ([vc isEqual:[tbc moreNavigationController]] &&
[[tbc viewControllers] indexOfObject:selected] > 3) {
return NO;
}
return YES;
}
这篇关于iPhone UITabbar项双击弹出控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!