Home Ask Login Register

Developers Planet

Your answer is one click away!

Chris G. 2 weeks ago

UIView is not updating when popToViewController on NavigationController

I have a navigationController where I pushViewController two viewcontrollers, OneViewController and TwoViewController. When I rotating the device on the pushed TwoViewController, and then popToViewController (see code) back to OneViewController the view on OneViewController is not updated / rotated.

enter image description here

If I then rotate on the OneViewController it then renders fine.

Do you know why it is not updating when using popToViewController?

        let viewControllers: [UIViewController] = self.navigationController!.viewControllers
        for aViewController in viewControllers {
            if aViewController is OneViewController {

                    aViewController.view.updateConstraints()
                    aViewController.view.setNeedsDisplay()
                    aViewController.view.layoutIfNeeded()
                    aViewController.view.setNeedsLayout()

                self.navigationController!.popToViewController(aViewController, animated: true)
                break
            }
        }

On the view I have also tried this:

override func viewWillShow(passingInAnyObject: AnyObject?) {
    self.updateConstraints()
    self.setNeedsDisplay()
    self.layoutIfNeeded()
    self.setNeedsLayout()
}

Answers


user8584904 2 weeks ago

Call the functionality which you want to update on the viewcontroller to which you pop in viewWillAppear method:

   override func viewWillAppear(animated: Bool) {
            super.viewWillAppear(animated) 
   }

Post Status

Asked in 2 weeks ago
Viewed 2,848 times
Voted 5
Answered 1 times

Search




Leave an answer


Quote of the day: live life