Test App
Test App

Reputation: 103

Swift after dismiss Current ViewController then the Presenting ViewController not calling viewWillAppear()

In my case, I am using two view controller VC1 and VC2. Here, VC1 button click to Present Modally and Over Full Screen presentation with Cross Dissolve Transition to presenting VC2. Now, from VC2 dismiss then I didn’t get call VC1 viewWillAppear().

I am not using code base for Present model. I am using Storyboard Segue.

Why it happening and how to fix this?

enter image description here

Upvotes: 1

Views: 885

Answers (2)

Deepak
Deepak

Reputation: 734

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.

To understand the concept you can refer to : https://medium.com/livefront/why-isnt-viewwillappear-getting-called-d02417b00396

Upvotes: 1

Shreeram Bhat
Shreeram Bhat

Reputation: 3157

From Docs,

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. 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.

Upvotes: 1

Related Questions