Reputation:
I have a today widget that contains two things:
UILabel
UITableView
In my viewWillAppear
I set the label to be visible and my tableView to be hidden and I set the label text to "Loading". See image below.
Then I get a location and when this is done, I call another method and
When this is successfully done I have a tableView that looks like this:
.
To my issue now.
When I open my today widget and hit viewWillAppear
, I don´t always manage to set my label and the only result I get is this
.
So what happens is that I can only show a bit of my previous result in the tableView.
This happens occasionally and it seems that the tableView freezes and I´m not able to update the initial view, to hide the tableView and show the label instead. Even when the screen freezes like this everything is running like it should and I manage to update the tableView and the view.
The only issue is when I open the widget that the screen freezes like this:
sometimes instead of showing my label. The reason it´s in the size as it is, is because I set the preferredContentSize = CGSizeMake(0, 30)
. Otherwise I bet it will have shown the entire previous tableView.
Any ideas of how to solve this, to always update the view when I hit viewWillAppear
?
Update
Starting another bounty to see if there is some other input on this issue.
Upvotes: 23
Views: 1316
Reputation: 588
You can put your operation in viewdidload()
, because viewdidload()
will be called when you enter you widget.
Upvotes: 0
Reputation: 38833
What the system does is that it takes a Snapshot. I have also been struggling a bit with this issue and I have checked this post but it did not solve my issue.
For the widgetPerformUpdateWithCompletionHandler
there are three options
NCUpdateResultNewData
— The new content required you to redraw the viewNCUpdateResultNoData
— The widget doesn’t require updatingNCUpdateResultFailed
— An error occurred during the update processIt does not matter which one of these is called it´s always the same result. And the system does take a Snapshot.
To help your widget look up to date, the system occasionally captures snapshots of your widget’s view. When the widget becomes visible again, the most recent snapshot is displayed until the system replaces it with a live version of the view.
To update a widget’s state before a snapshot is taken, be sure to conform to the NCWidgetProviding protocol. When your widget receives the widgetPerformUpdateWithCompletionHandler: call, update your widget’s view with the most recent content and call the completion handler, using one of the following constants to describe the result of the update
I think that we´re maybe trying to load to "heavy" data and this could occur because of that. This is my answer, but I started a bounty to check if someone else has another answer or if you agree with my post.
Upvotes: 10