Dynamic page-based Apple Watch app Dynamic page-based Apple Watch app objective-c objective-c

Dynamic page-based Apple Watch app


You can present page based navigation from code. You can specify as many pages as you want, but those pages has to be designed in the Storyboard

func presentControllerWithNames(names: [AnyObject], contexts: [AnyObject]?) // modal presentation of paged controllers. contexts matched to 

Example

Present Page Interfaces for objects. This code show page for every object

let objects  = ["1", "2", "3", "4", "5"]let controllers = Array(count: objects.count, repeatedValue: "Page")presentControllerWithNames(controllers, contexts: objects)

Present different Interface for different object object.

let objects  = [1, 2, 3, 4, 5]let controllers = objects.map { object  in object % 2 == 0 ? "Even-Page" : "Odd-Page" }presentControllerWithNames(controllers, contexts: objects)


In root interface controller's awakeWithContext method, use WKInterfaceController.reloadRootControllersWithNames class method.

let objects  = ["1", "2", "3", "4", "5"]let controllers = Array(count: objects.count, repeatedValue: "Page")WKInterfaceController.reloadRootControllersWithNames(controllers, contexts: objects)


I couldn't get these answers to work because I was missing an important part, you need to create a second interface controller with its identifier as the controller name. See here for more info: https://stackoverflow.com/a/28955247/945247