Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 Today Widget not calling viewDidLoad

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)
}
like image 713
Jason Hocker Avatar asked Aug 31 '15 20:08

Jason Hocker


People also ask

How many times does viewDidLoad get called?

viewDidLoad() is one of the initialization methods that is called on the initial view controller. viewDidLoad() is called before anything is shown to the user - and it is called only once.

Does viewWillAppear get called before viewDidLoad?

viewWillAppear(_:) Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called.


1 Answers

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.

like image 123
Christopher Pickslay Avatar answered Sep 30 '22 17:09

Christopher Pickslay