viewWillAppear 在选项卡栏的视图控制器中
在我的选项卡栏中,我有四个视图控制器,其中一个视图控制器中发生的情况可能会影响另一个视图控制器的视图,因此当视图控制器变得可见时,我可能需要重新加载视图控制器中的某些元素。通常我会通过实现 viewWillAppear 来解决这个问题,但是当我在选项卡之间切换时, viewWillAppear 似乎不会被调用。我该如何解决这个问题,或者我应该做什么?
更新:作为 PS,我应该补充一点,这是导航控制器层次结构中的选项卡控制器
干杯
Nik
In my tab-bar I have four viewcontrollers, and what happens in one can affect the view of the other, so I may need to reload some elements in the viewcontroller when it becomes visible. Normally I'd fix that by implementing viewWillAppear, but when I switch between the tabs, viewWillAppear does not seem to get called. How can I fix that, or what should I do instead?
Update: as a PS I should add that this is a tabbarcontroller in a navigationcontroller hierarchy
Cheers
Nik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用选项卡控制器委托,就像魅力一样
You may use the tabbar controller delegate works like a charm
请在此处查看我的答案
iPhone viewWillAppear 未触发
Please see my answer here
iPhone viewWillAppear not firing
如果您发现这个问题,因为您想更新
UITabBarController
本身中的某些内容,而不是UITabBarController
的UIViewControllers
,如 OP 的问题。例如,隐藏或显示自定义UITabBarButton
。在 Swift 3.0 中,重写UITabBarController
类的setNeedsStatusBarAppearanceUpdate
对我有用。And in case you find this question because you would like to update something in the
UITabBarController
itself, not theUIViewControllers
of aUITabBarController
, like the OP's question. For example, hiding or displaying a customUITabBarButton
. In Swift 3.0 overridingsetNeedsStatusBarAppearanceUpdate
of myUITabBarController
class worked for me.viewWillAppear
只能在视图出现时使用,而不是在更新视图时使用。请在
viewController
的视图上使用setNeedsDisplay
。viewWillAppear
should only be used when the view appears, and not for updating it.Use
setNeedsDisplay
on theviewController
's view instead.