Search code examples
iosobjective-cwatchkit

Odd behavior when updating interface as part of willActivate


I have a WKInterfaceController subclass that shows a 6 row WKInterfaceTable. This class is also initial interface controller. When receiving a notification action via handleActionWithIdentifier:forLocalNotification I am modally presenting a second interface controller. The user takes no action on the modally presented interface controller, but loading it modifies the state of one of the 6 objects used by the row controllers in the initial interface. When the modal controller is dismissed, my intent is to reflect the updated state in the table.

I have no issues retrieving the updated objects since their management is handled by another class that I can simply query for updated data. Since the initial interface controller has already executed awakeWithContext:, I can only rely on willActivate to updating the interface. This seems to be in line with Apple's guidelines since I'm not initializing the interface as part of that method, merely updating it.

TL;DR;

When I update the rows via the row controller, only the value that was updated is displayed properly on the cells. The other cells use the default values assigned to the labels in my cell at design time on the storyboard.

For example

  • Row 1: Count - 3 Best - 3
  • Row 2: Count - 42 Best - 99
  • Row 3: Count - 42 Best - 99

The extremely curious part is that this only happens on subsequent calls to willActivate. When just opening the watch app and updating the interface for the first time in willActivate it behaves as expected. When being activated as a result of the modal dismissing, this behavior creeps up.

Thanks for any ideas.


Solution

  • I can think of two possible issues.

    First, the WatchKit interface controllers behave as though they are snapshotted in page sets. After they have been displayed once, the values won't update after being deactivated until they are fully on screen and your willActivate method has been called. Switching images has the same as switching a table row label when the interface isn't visible. It MUST be done in willActivate otherwise it appears to get dropped.

    The other problem I've seen related to this is when you setNumberOfRows, you need to update the values in ALL rows. Otherwise you will end up with customized row values for the ones you set, and the default values from the storyboard for all other rows. If you're only updating the values for a particular row in willActivate and not calling the setNumberOfRows on the Table, then I'd say you should file a bug with Apple's Bug Reporting System.