TabBarController 委托不起作用
任何人都可以帮助我吗 当我使用 UITabBarController 委托时它不起作用..
我调用了这样的委托方法..
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[self.navigationController popToRootViewControllerAnimated:NO];
}
Can any one help me,
when i am using my UITabBarController delegate it is not working..
I called a delegate method like this..
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[self.navigationController popToRootViewControllerAnimated:NO];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
阅读文档以更深入地了解导航控制器之间的关系, tabBar 控制器,以及视图和导航层次结构。
然后检查您提供的代码。哪个视图/控制器是容器?您正在弹出 self 的 navigationController,它与 tabBarController 不同。如果您想在选项卡之间切换,我认为您实际上并不需要此方法。
尝试注释掉这个方法。它是 UITabBarController 委托协议中的一个可选方法。如果将其注释掉,您应该获得选项卡控制器的默认行为,即选择适当的 viewController 并切换到新视图。
通常,仅当您希望在视图控制器之间切换时执行某些操作时,才需要使用此方法。
Read the documents to get a deeper understanding of the relationships between navigation controllers, tabBar controllers, and the view and navigation hierarchy.
Then review the code you've provided. Which view/controller is the container? You are popping the navigationController of self, which is not the same as the tabBarController. I don't think you actually need this method if you are looking to switch between tabs.
Try commenting out this method. It is an optional method in the UITabBarController delegate protocol. If you comment it out, you should get the default behavior of the tab controller, which should be to select the appropriate viewController and switch to the new view.
You typically only need to use this method if you want some action taken as you switch between view controllers.
如果您正在做的是子类化 UITabBarController,那么...奇怪的是...您可以通过将自身设置为委托来使其工作:
然后 didSelectViewController 操作将正常触发:
不要忘记将 UITabBarControllerDelegate 类添加到你的 .h 文件:
If what you're doing is subclassing a UITabBarController, then... oddly enough... you can get it working by setting itself as a delegate:
Then the didSelectViewController action will fire normally:
Don't forget to add your UITabBarControllerDelegate class to your .h file:
如果您通过扩展 UITabBarController 并尝试以编程方式更改选项卡栏选定索引来使用选项卡栏自定义,那么它将不会调用委托。
请参阅“UITabBarDelegate”内的注释:
If you are using tab bar customizing by extending UITabBarController and trying to change tab bar selected index programmatically then it will not call delegates.
Please see the note inside "UITabBarDelegate":
这可能对你有帮助
This might help you
指定
UITabbarcontrollerDelegate
在 .h 文件中
然后
specify
UITabbarcontrollerDelegate
in .h filethen