“更多”上选定的索引UITabbar 的视图
如何管理 UITabBar 的“更多”视图上的用户选择?我有这段代码来管理 UITabBarItems 选择:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (!(viewController == tabBarController.moreNavigationController)) {
int index = tabBarController.selectedIndex;
[[DataManager sharedInstance] setCurrentTabbarIndex:index];
}
}
它对于可见的 UITabBarItems 工作得很好,但是当用户从“更多”视图中选择某个项目时,我永远不会收到通知。有没有办法捕获“更多”视图的用户项目选择?谢谢!
How can I manage the user selection on the "more" view of a UITabBar? I have this code to manage the UITabBarItems selections:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (!(viewController == tabBarController.moreNavigationController)) {
int index = tabBarController.selectedIndex;
[[DataManager sharedInstance] setCurrentTabbarIndex:index];
}
}
It works fine for the visible UITabBarItems, but when the user select some item from the "more" view I never get informed about that. Is there some way to catch the user item selection of the "more" view? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
UITabBarController 的“更多”视图与其他视图分开处理。苹果公司对此主题的讨论如下:
由此看来,我认为你可以这样做:
The "more" view of a UITabBarController is handled separately from the other views. Apple's discussion on this subject says the following:
Judging from that I would think that you can do something like:
对于一个非常古老的问题来说,这是一个很晚的答案,但无论如何,它就在这里,以防有人偶然发现这一点。
解决方案是将您自己指定为“更多”导航控制器的委托。您已经有一个采用
UITabBarControllerDelegate
协议的类,因此 .h 文件可能如下所示:无论您将类指定为委托,请执行以下操作:
最后,在您的委托类中添加此方法:
请注意,当您以编程方式更改选项卡时,不会调用任何委托方法。
A very late answer for a very old question, but here it is anyway, in case someone stumbles upon this.
The solution is to assign yourself as the delegate of the "more" navigation controller. You already have a class that adopts the
UITabBarControllerDelegate
protocol, so the .h file might look like this:Wherever you are assigning your class as delegate, do this:
And finally, in your delegate class add this method:
Note that none of your delegate methods are invoked when you change tabs programmatically.
我发现解决这个问题的最佳方法是成为 UITableView 的委托,它是 UITabBarController.moreViewController 中的 topViewController。
实现 didSelectRowAtIndexPath 应该可以解决问题!
Stuart Sharpe 在他的博客中描述了最佳(也是最安全)的实现:http://initwithstyle.net/2014/02/making-more-of-the-more-view/
The best approach I've found for this problem is to become the delegate for the UITableView which is the topViewController in the UITabBarController.moreViewController.
Implementing the didSelectRowAtIndexPath should solve the problem!
The best (and most secure) implementation for this is described by Stuart Sharpe in his blog: http://initwithstyle.net/2014/02/making-more-of-the-more-view/
无论选择什么视图,都会收到
viewWillAppear:animated:
在选项卡栏控制的每个视图中提供此信息,因此即使是从“更多”控制器进行的选择,您也可以提取用户选择的标识。
您可以在此方法中保存标签栏状态,也可以为您的视图提供对标签栏的引用并通知它。
Whatever view is being selected will receive
viewWillAppear:animated:
Provide this in every view that's controlled by your tab bar, and you can thus extract the identity of the user's selection even when made from a "More" controller.
You can save the tab bar state right in this method, or you can provide your views with a reference back to the tab bar and notify it.