UITabBarController 奇怪吗?
如果我通常加载 UITabBarController
并在视图之间切换,它会调用每个视图控制器的 viewWillAppear
。 但事实并非如此。
我想在触摸另一个选项卡后立即切换到另一个选项卡。
如果我指定要加载的选项卡 - 例如 [self.tabBarController setSelectedIndex:0 ]
在其中一个选项卡(例如选项卡 4)的 viewWillAppear
中...它立即返回到选项卡 0。
但在那之后....它不会调用 viewWillAppear
在任何当我在选项卡之间切换时。 例如,如果我再次转到选项卡 4,它不会返回到选项卡 0。我希望它会通过一个永无止境的循环,因为我希望一旦触摸选项卡 4,选项卡 0 就会加载。
但它仅运行一次!!
为什么 ??
注意:问题已被编辑。
If I normally load up a UITabBarController
and switch between views, it calls the viewWillAppear
of each view controller.
But it is not so.
I want to switch to another tab as soon as another tab is touched.
If I specify a tab to load up - for example [self.tabBarController setSelectedIndex:0]
in the viewWillAppear
of one of the tabs (say tab 4)... It goes immediately back to tab 0.
But after that.... it does not call the viewWillAppear
on any of the tabs when I switch between them.
For example, if I again go to tab 4, it does not come back to tab 0. I expect it to by a never ending cycle as I expect tab 0 to load up as soon as tab 4 is touch.
But it runs JUST ONCE !!
Why ??
Note: Question has been edited.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我找到了解决方案。 每次您单击选项卡时它都会起作用,并且它会在两个选项卡上调用 viewWillAppear。
您可以在您的 AppDelegate(或 UITabBarController 委托中的其他位置)中执行此操作:
示例代码:
I think I found a solution. It works every time you click on your tab and it calls viewWillAppear on both tabs.
You can do this in your
AppDelegate
(or somwhere else in UITabBarController's delegate):Sample code:
设置 selectedIndex 不会更改 selectedViewController。您必须更改 selectedViewController 本身。有关更多信息,请参阅文档细节。
setting the selectedIndex won't change the selectedViewController. You will have to change selectedViewController itself. Look at the documentation for more details.