-1

I am working on some old code that I didn't write, and it's really not architected well...

The situation is that a view controller presents a custom view controller modally, however every 30 seconds the presenting view controller is recreated.

The issue here is that if the modal is on screen when this happens, then any effort to dismiss it results in odd behaviour (such as a white screen).

I have tried calling [self.presentedViewController dismissViewControllerAnimated]; on the newly recreated controller, but presentedViewController is nil as you would expect.

I have also tried keeping a weak reference to the modal view controller, then when the presenting VC is reloaded, setting this value to that of the old VC. This has allowed me to call self.customModalVC dismissViewControllerAnimated]; but this is causing the aforementioned white screen, perhaps because it's presenting VC is no longer in the stack?

Any and all suggestions appreciated.

Jacob King
  • 6,025
  • 4
  • 27
  • 45
  • why is it recreated every 30 sec.? this sounds a bit strange to me. I also see now way to keep this modal view presenting without holding a reference to it which would probably leed into memory issues due to the fact that you would need to hold a ref to the viewController holding it. So your best bet sounds like refactoring/changing this. – zero3nna Feb 21 '17 at 15:04
  • It's due to network calls, I agree it's a totally stupid way of doing it. Wouldn't have been my approach. Looks like I don't really have many options other than a refactor... PM is going to love a 4h ticket going to a 3d ticket haha. – Jacob King Feb 21 '17 at 15:14
  • yep, that sounds like a fun ticket to do. – zero3nna Feb 21 '17 at 15:28

1 Answers1

-1

Try passing the navigation controller to newly presented ViewController:

    presentedVC.navigation = self.navigationController

Add this to newly created one for dismissing

    self.dismiss(animated: false) { 
                _ = self.navigation?.popViewController(animated: true)
            }
Anuraj
  • 1,242
  • 10
  • 25