Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

触发左菜单时的vc,会触发vc的viewWillAppear问题 #39

Open
hugolubingshen opened this issue Feb 27, 2018 · 6 comments
Open

Comments

@hugolubingshen
Copy link

如题,为什么呢?就弹出个左菜单,能不触发吗?

@ChavezChen
Copy link
Owner

本质是present出来的。和正常present另一个界面是一样的,所以会走vc的所有生命周期函数。如果你不希望执行viewwillappear里面的部分代码,可以事先做一个标记让它不执行或者看能不能把代码搬迁到其他位置。

@hugolubingshen
Copy link
Author

我知道是present的,但是侧边栏一启动,就是present后,开启的vc的viewwillappear就触发了,正常present是关闭之后,触发present的vc才会触发viewwillappear

@ChavezChen
Copy link
Owner

你是说 当 A present B 的时候。A的viewwillappear方法也调用了是吗? 这个是因为在自定义转场结束的时候,调用[transitionContext completeTransition:YES];这个方法系统会把A的视图从containerView中移除掉,于是我在后面手动将 A的视图重新加到containerView中。。这样才能显示到界面上,于是addsubview:A.view]这一操作会造成A的viewwillappear方法调用。

@hugolubingshen
Copy link
Author

对,就是这样,有办法解决吗?我现在需求是点解侧边栏切换模式,viewwillappear再重新加载数据,我不想触发两次viewwillappear

@hugolubingshen
Copy link
Author

或者说,我在viewwillappear加个判断,我本地存储一个变量判断,但是怎么知道现在是关闭,还是开启呢?

@ChavezChen
Copy link
Owner

show的时候 设置标记为YES,然后在viewwillAppear里面判断这个标记为YES,就将此标记设置为NO,同时return,不执行后面的代码。


- viewwillapear {
  [super ...];
  if (flag == YES) {
     flag = NO;
     return;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants