viewWillDisappear 在选项卡栏项目选择视图控制器集时调用
场景如下:
- Window 创建一个选项卡栏控制器,并添加多个选项卡栏项目视图控制器,并将
UINavigationController
作为顶部视图。 viewWillAppear
在第一个选项卡栏视图上被调用。- 用户点击第一个选项卡视图上的控件,将视图控制器推送到导航堆栈上。
viewWillDisappear
被调用。 - 用户交互后,视图将从导航堆栈中弹出。
viewWillAppear
被调用。 - 用户点击某些内容会导致另一个视图被推送到导航堆栈上。
viewWillDisappear
被调用。 - 用户点击某些内容会导致代码在选项卡栏控制器上设置 selectedViewController 。
viewWillDisappear
在第一个选项卡栏项目的主视图上再次被调用。
有什么想法吗?
Here's the scenario:
- Window creates a tab bar controller and adds multiple tab bar item view controllers with a
UINavigationController
as the top view. viewWillAppear
gets called on the first tab bar view.- The user taps a control on the first tab view that pushes a view controller on the nav stack.
viewWillDisappear
gets called. - After user interaction, the view is popped off the nav stack.
viewWillAppear
is called. - User taps something which causes another view to be pushed on the nav stack.
viewWillDisappear
is called. - User taps something which causes the code to set the selectedViewController on the tab bar controller.
viewWillDisappear
gets called AGAIN on the main view for the first tab bar item.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终通过保留一个 BOOL 来解决这个问题,它会告诉我是否需要执行 viewWillDisappear 工作。丑陋但有效。我希望有更好的解决方案,或者我正在做一些明显错误的事情。
I ended up working around this by keeping a BOOL that would tell me if I need to perform the viewWillDisappear work or not. Ugly but it works. I was hoping there would be a better solution or that I was doing something that was obviously wrong.