1

I have view controller A that can modally present view controller B or view controller C, which is a screen we are using to capture a signature. In view controller C, I am using the following code to rotate the screen to landscape:

appDel.shouldRotate = true
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
UIViewController.attemptRotationToDeviceOrientation()

where in the app delegate I am using

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return shouldRotate ? .landscape : .portrait
}

Normally, I am able to dismiss view controller C without any problems. However, if I restore the app state and display view controller A and present view controller C then proceed to dismiss C, the app returns to the home screen of our app (the initial screen) as opposed to dismissing back to A. The weird thing is that I can present and dismiss view controller B without this problem occurring.

I have commented out my screen rotation logic and I can dismiss view controller C without any problems.

So why does changing the screen's orientation prevent me from going back to view controller A after dismissing C?

Michael McKenna
  • 811
  • 1
  • 11
  • 24
  • By goes back to the homescreen, you mean that the app crashes, or goes into the background? – jlmurph Jul 09 '17 at 18:28
  • @murphguy I meant that it goes back to the first screen in our app. I'll make this clarification in my post. – Michael McKenna Jul 09 '17 at 18:29
  • Which VC controls the delegates for C? VC A or the first screen/VC? And from which of those two is C instantiated from? – jlmurph Jul 09 '17 at 18:30
  • VC controls the delegates for C. C is instantiated from A via a modal segue – Michael McKenna Jul 09 '17 at 18:35
  • Are all VC's nested within a navigation controller at the top level? – jlmurph Jul 09 '17 at 18:39
  • Correct. Also that got me thinking, so I printed off the view controllers in the stack in VC A and after first getting to that screen (no state preservation), I was able to print all of the view controllers. However, after state preservation, the navigation controller was nil. Hmm...I have restoration IDs set for everything. You think this has something to do with my problem? – Michael McKenna Jul 09 '17 at 18:44
  • 1
    Yeah i'd be willing to bet it is. Judging by the post bellow, i'd try moving your orientation/logic Variables to the nav controller's class. check the comments on OP's question and the selected answer: https://stackoverflow.com/a/40427513/7183483 – jlmurph Jul 09 '17 at 18:52
  • So you could change up the vars in your nav controller class based on some global variables or some custom variables with strong references that you change based on which VC you present, that way you can customize which results to return etc. – jlmurph Jul 09 '17 at 18:54
  • My navigation controller is nil upon app restoration and I have no idea why. Should I open a new question? – Michael McKenna Jul 09 '17 at 20:12
  • Might be a good idea yeah. Is the nav controller instantiated programmatically or by storyboard? – jlmurph Jul 10 '17 at 19:43
  • Doing it by storyboard – Michael McKenna Jul 10 '17 at 20:11
  • Can you put the classes in a gist file on github? I could have a look at it sometime today – jlmurph Jul 11 '17 at 17:24

1 Answers1

0

Thanks to my discussion with murphguy, I concluded that this is caused by the navigation stack not being restored upon app restoration. Embedding VC C in a navigation controller, unfortunately, did not solve the issue. Why the navigationController for VC A upon restoration, I don't know. However, I made a new question to figure that out at Why isn't my navigation stack being preserved upon restoring the app?.

Michael McKenna
  • 811
  • 1
  • 11
  • 24