Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic number of pages in Watchkit Page Navigation

Tags:

swift

watchkit

Is there any way dynamically create pages in a page-based navigation? In every example I read, the pages were created as Interface Controllers and linked in the Storyboard.

like image 341
Dănuț Mihai Florian Avatar asked Jan 25 '15 01:01

Dănuț Mihai Florian


2 Answers

Here is the way to do it

WKInterfaceController.reloadRootControllersWithNames(["pageController", "pageController"], contexts: ["pageController", "pageController"])
like image 200
Dănuț Mihai Florian Avatar answered Oct 22 '22 11:10

Dănuț Mihai Florian


To avoid infinite loop use:

static BOOL first = YES;
- (void)willActivate {
    // This method is called when watch view controller is about to be visible to user
    [super willActivate];

    if (first) {
        [WKInterfaceController reloadRootControllersWithNames:[NSArray arrayWithObjects:@"SinglePageICIdentifier",@"SinglePageICIdentifier", nil] contexts:[NSArray arrayWithObjects:@"First",@"Second", nil]];
        first = NO;
    }

}
like image 26
Gamma-Point Avatar answered Oct 22 '22 10:10

Gamma-Point