Page-based Apple Watch Dynamic App

I tried to create a page-based Apple Watch app.

As far as I can see, you can create a fixed number of pages for your application in a storyboard.

So, I just wonder if there is a way to dynamically programmatically create pages for your application based on the loaded data?

Ie: newspaper app in which users can scroll left and right to switch to different articles.

thanks

+7
ios objective-c swift watchkit
source share
3 answers

You can imagine page-based navigation from code. You can specify as many pages as you want, but these pages must be designed in a storyboard

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

Example

Present Page Interfaces for objects. This page shows the code for each object.

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

Present a different interface to another object of the 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) 
+10
source share

On the awakeWithContext root interface controller, use the class method WKInterfaceController.reloadRootControllersWithNames.

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

I could not get these answers to work, because I missed the important part, you need to create a second interface controller with its identifier as the name of the controller. See here for more information: fooobar.com/questions/219838 / ...

0
source share

All Articles