Search code examples
seguewatchkitwatchos-2

How to detect which sequence is in page segue for WatchKit?


I'm trying to implement a page-based navigation app using the "Next Page Relationship Segue" described in this tutorial.

In the app, both calendar views show the same type of content. The first one contains today's activities, and swiping presents the second one which contains tomorrow's activities.

I'd like to re-use the same code (i.e., same class) for both interface controllers. Then, when each loads, I need to know which one it is, in order to display the activities for today or tomorrow. Is there any way (such as a delegate method) to detect which one it is?

If there is no way to find out, is it the best way to create a parent class with all the code, and create sub-classes for today and tomorrow views?


Solution

  • All a particular interface controller would know is its context, and whether it's been (de)activated.

    Since you're not presenting modal page-based controllers, there's no context which would be passed at initialization to specify today or tomorrow for a particular page.

    The swipe navigation doesn't pass any context from one page to the next, so that doesn't offer a way to identify which current page a particular controller would be.

    You'll need to create separate (sub)classes for the today and tomorrow interface controllers, and have each display its specific data for that day.