Reputation: 7067
The today widget is drawn correctly when it is added to the today view. But if you user comes back to it later, the viewDidLoad function is not called and it is showing stale data. Should viewDidLoad be called everytime? Is there an iOS 9 / Xcode 7 beta 6 bug?
Edit: Added that widgetPerformUpdateWithCompletionHandler not called either. I have breakpoints set and print functions
func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)) {
print("in widgetPerformUpdateWithCompletionHandler")
fetch()
completionHandler(NCUpdateResult.NewData)
}
Upvotes: 6
Views: 3485
Reputation: 17762
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.
Upvotes: 5
Reputation: 7067
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")
}
}
Upvotes: 0