willActivate raised by next page before getting selected

Hi,


I'm having a weird problem with a page based application. I create multiple pages in SW by calling reloadRootControllersWithNames(pages, contexts: pageContexts). Everything works fine and the app populates the pages accordingly to the context. Anyway, it seems willActivate is raised both by the currently showing page and the next one. Once the user swipes into the next page, willActivate is again raised both on the newly showed page and the next one. It was supposed to be called only on the one that's showed on screen! As I get willActivate called multiple times I have no way to know which page is actually selected!

Once the user swiped through all the pages, it stops this weird behavior and begins working as expected (willActivate called only once, for the current page).


The problem occurs both in Watchkit and WatchOS 2 on actual devices but not in the simulator.

It is easily reproducible by logging self in willActivate, even by creating a multi-page storyboard.


Anyone else? Did I misunderstood how it should work?


Thanks in advance!


Marco

Answered by tom_witkin in 18913022

This is expected behavior. The page controller will pre-load the next/previous pages before they are onscreen. To track which one is visible, you can use the new appearce methods on WKInterfaceController (coming in a future seed):


- (void)didAppear;
- (void)willDisappear;
Accepted Answer

This is expected behavior. The page controller will pre-load the next/previous pages before they are onscreen. To track which one is visible, you can use the new appearce methods on WKInterfaceController (coming in a future seed):


- (void)didAppear;
- (void)willDisappear;

This was introduced in watchOS 1.0.1, presumably to make apps seem faster.


As Tom says you can get around it easily by using didAppear in watchOS 2, but if you are targeting watchOS 1.0.1 then there is a thread of possible workarounds on the old dev forums:


https://devforums.apple.com/message/1136878#1136878

willActivate raised by next page before getting selected
 
 
Q