[英]Swift after dismiss Current ViewController then the Presenting ViewController not calling viewWillAppear()
In my case, I am using two view controller VC1
and VC2
. 就我而言,我正在使用两个视图控制器VC1
和VC2
。 Here, VC1 button click to Present Modally
and Over Full Screen
presentation with Cross Dissolve
Transition to presenting VC2. 在这里,VC1按钮单击以通过Cross Dissolve
过渡到模式VC2来呈现Present Modally
和Over Full Screen
演示。 Now, from VC2 dismiss then I didn't get call VC1 viewWillAppear()
. 现在,从VC2关闭,然后我没有接到VC1 viewWillAppear()
。
I am not using code base for Present model. 我没有为Present模型使用代码库。 I am using Storyboard Segue
. 我正在使用Storyboard Segue
。
Why it happening and how to fix this? 为什么会发生以及如何解决此问题?
Note 注意
If a view controller is presented by a view controller inside of a popover, this method is not invoked on the presenting view controller after the presented controller is dismissed. 如果视图控制器是由弹出框内的视图控制器提供的,则在关闭所提供的控制器后,不会在呈现的视图控制器上调用此方法。
So according to the documentation when a ViewController presents another ViewController modally this method will not be called. 因此,根据文档,当ViewController以模态形式提供另一个ViewController时,将不会调用此方法。 To fix this you need to use 要解决此问题,您需要使用
func dismiss(animated flag: Bool,
completion: (() -> Void)? = nil)
and move(or repeat) some of viewWillLoad logic to completion handler. 并将一些viewWillLoad逻辑移动(或重复)到完成处理程序。
Change presentation to Full screen
or If you want to stick to Over Full Screen
then make vc2 delegate of vc1 and call delegate method on dismiss. 将演示文稿更改为Full screen
或者如果您要坚持Over Full Screen
则使vc2成为vc1的委托,并在关闭时调用委托方法。
To understand the concept you can refer to : https://medium.com/livefront/why-isnt-viewwillappear-getting-called-d02417b00396 要了解该概念,您可以参考: https : //medium.com/livefront/why-isnt-viewwillappear-getting-called-d02417b00396
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.