BUG in OS?: awakeWithContext/init called too late

If I use presentControllerWithName, or pushControllerWithName in a hierarchical Apple Watch app, this is what happens:


1. Watch OS presents the view onscreen

2. Watch OS calls init, awakeWithContext


But this is terrible, I never get a chance to update the UI contextually depending on the user's state. It's only after the view controller is animated onscreen that I can adjust the UI, which results in ugly flashing as I show/hide UI objects.


Is this a bug in the OS? Or am I doing something wrong?

Replies

I have the same issue as you are having.

Hopefully it's clasified as a problem, so that they fix it, but perhaps it's not.

I filed a bug report. Let's see if they fix it.

This is expected, but please file a bug report if you think this should behave differently.


bugreport.apple.com

How is this expected?


According to https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/#//apple_ref/occ/instm/WKInterfaceController/willActivate:


The system calls this method to notify the interface controller that its content is about to be displayed onscreen


And we know that WillActivate gets called after awakeWithContext. This shows a contradiction with your statement of "behaviour as a expected", no?

The content is not shown until those two methods are called. The controller itself can appear, but the content remains hidden.

The content is clearly shown before those two methods are called. The content does not remain hidden.


I'm running the latest watch os 2 beta (downloaded a couple of days ago). Also tried this on the simulator with xcode 7 beta 5..


What happens: the controller appears with all its UI intact, then init/awakeWithContext is called. awakeWithContext is supposed to be the method for setting up the UI. But if you use that or init to set up the UI, you get a nasty UI flash. For example, if I need to hide/show UI objects depending on the user's state.


The way it works presently can't be correct. There's no way to preflight the UI according to the app state/user state the way it works now.


ALSO: I did file a bug report.

And if anyone else is seeing this, please file a bug report. I'd hate for watch OS 2 to ship without being able to prevent nasty UI flashes.

If you select "Shows Activity Indicator when Loading" for an interface controller in IB, you will get a spinner in place of your content until awakeFromContext has returned.