简体   繁体   English

当选择选项卡栏项目视图控制器时调用viewWillDisappear

[英]viewWillDisappear called when tab bar item selected view controller set

Here's the scenario: 这是场景:

  1. Window creates a tab bar controller and adds multiple tab bar item view controllers with a UINavigationController as the top view. Window创建一个选项卡栏控制器,并添加多个带有UINavigationController作为顶视图的选项卡栏项目视图控制器。
  2. viewWillAppear gets called on the first tab bar view. 在第一个标签栏视图上调用viewWillAppear
  3. The user taps a control on the first tab view that pushes a view controller on the nav stack. 用户点击第一个选项卡视图上的控件,该控件将视图控制器推入导航堆栈。 viewWillDisappear gets called. viewWillDisappear被调用。
  4. After user interaction, the view is popped off the nav stack. 用户交互后,该视图会从导航堆栈中弹出。 viewWillAppear is called. viewWillAppear被调用。
  5. User taps something which causes another view to be pushed on the nav stack. 用户点击某些内容会导致另一个视图被推入导航堆栈。 viewWillDisappear is called. viewWillDisappear被调用。
  6. User taps something which causes the code to set the selectedViewController on the tab bar controller. 用户点击某些东西,使代码在选项卡栏控制器上设置selectedViewController。 viewWillDisappear gets called AGAIN on the main view for the first tab bar item. viewWillDisappear在第一个选项卡栏项目的主视图上被称为AGAIN。

Any ideas? 有任何想法吗?

I ended up working around this by keeping a BOOL that would tell me if I need to perform the viewWillDisappear work or not. 最后,我通过保留一个BOOL来解决此问题,该BOOL会告诉我是否需要执行viewWillDisappear工作。 Ugly but it works. 丑陋但行得通。 I was hoping there would be a better solution or that I was doing something that was obviously wrong. 我希望会有更好的解决方案,或者我做的事情显然是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM