Search code examples
iosswiftwidgettableviewtoday-extension

Today Widget tableView freezes


I have a today widget that contains two things:

  1. A UILabel
  2. A UITableView

In my viewWillAppearI 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

  1. If I do not find any data I just update the label text to "Did not find data"
  2. Otherwise I set the label to be hidden and the tableView to be visible and I start updating the data

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.


Solution

  • 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

    1. NCUpdateResultNewData — The new content required you to redraw the view
    2. NCUpdateResultNoData — The widget doesn’t require updating
    3. NCUpdateResultFailed — An error occurred during the update process

    It 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

    Reference.

    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.