iOS 9 Today Widget not calling viewDidLoad iOS 9 Today Widget not calling viewDidLoad xcode xcode

iOS 9 Today Widget not calling viewDidLoad


When you scroll a widget off and back on screen, the same controller instance will be reused for a short amount of time (appears to be ~30 seconds in my testing), and viewDidLoad and widgetPerformUpdateWithCompletionHandler: will not be called.

However, viewWillAppear and viewDidAppear will be called every time your widget is displayed.


Posting my own answer, but would like discussion on this code - should it be there or how to properly do it?. We had in this method, and by removing it the widget began to work correctly

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator){    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)    if let safeCoordinator = coordinator as UIViewControllerTransitionCoordinator?    {        print("coordinator != nil")        safeCoordinator.animateAlongsideTransition({ context in            self.tableView.frame = CGRectMake(0, 0, size.width, size.height)            }, completion: nil)    }    else    {        print("coordinator == nil")    }}