0

Using iOS-9.2 and Swift-2.1:

Getting back to my rootViewController using the below code, unfortunately leads to a very strange behaviour of the status-bar of my App !

    static func returnToRootViewController(sender: AnyObject) {

    let initialscene = sender.storyboard?!.instantiateInitialViewController()
    for _ in sender.view!!.window!.subviews {

        sender.dismissViewControllerAnimated(true, completion: nil)
    }
    sender.view!!.window!.rootViewController = initialscene
    }

The two images below show the status bar in its normal condition (i.e. left image) and after returning by above returnToRootViewController-Code (i.e right image with strange coloring) !

Prior to applying the above code, the navigation-controller was navigated to severeal modal popovers....

Any help on this appreciated !

enter image description here

iKK
  • 6,394
  • 10
  • 58
  • 131

1 Answers1

1

You're dismissing the same viewcontroller several times. Calling dismissViewController will only dismiss the one presented by the sender, not the several underneath it (I'm assuming sender is the topmost one)

From this answer, it sounds like you might be able to dismiss all of them just by dismissing the first one presented by your rootViewController: https://stackoverflow.com/a/23566262/78496

Community
  • 1
  • 1
chedabob
  • 5,835
  • 2
  • 24
  • 44
  • Hmm, I had before only: "self.dismissViewControllerAnimated(true, completion: nil)" - but this went back just one ViewController instead of going to the rootViewController. Any idea on how to get to rootViewController without the status-bar problem ? – iKK Jan 08 '16 at 22:51
  • By the way, I am in the middle of a pageViewController - trying there to attempt to go back to the rootViewController... – iKK Jan 08 '16 at 22:55