The page-based interface uses several identical dispatchers

I want to create a page-based interface in WatchKit.

The docs indicate that you need to create several interface controllers and link them to create a page-based interface.

Imagine that I have several objects, and for each object I want to display information in Watch. Then I want to use page-based navigation to move on to the next element. All elements use the same interface controller, but with different data.

Is there any way to achieve this?

+4
source share
2 answers

, InterfaceController , , :

  • , .
  • "willActivate" , (interfaceViewControllers).
  • WKInterfaceController.reloadRootControllersWithNames(, : pageContexts).
  • "awakeWithContext" ControlController , /.

β„–. 3 , , . , , - self.presentControllerWithNames, "".

: SplashScreen

override func willActivate() {
    super.willActivate()
    let pages = ["page1","page2","page3","page4"]
    let pageContexts = [["data1":0,"data2":0],["data1":38,"data2":1],["data1":49,"data2":1],["data1":74,"data2":2]]
    WKInterfaceController.reloadRootControllersWithNames(pages, contexts: pageContexts)
}

override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)

    if let contextDict:Dictionary = context as Dictionary<String,AnyObject>!
    {
        data1 = contextDict["data1"] as Int
        data2 = contextDict["data2"] as NSTimeInterval
    }
}
+4

, , reloadRootControllersWithNames willActivate .

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;
    }
}
0

All Articles