I am working on Apple watch. I am tried to pass the array data from one
The WatchKit method for passing objects to a page-based WKInterfaceController is different than in iOS. While you will see a relationship segue on the Storyboard, when you click on it there is no option to name this segue (which is the first step to using the
prepareForSegue: method in iOS).
Rather, what you do is pass one array that contains "context" objects, one of which will be provided to each WKViewController that is managing a page. In Objective-C:
+ (void)reloadRootControllersWithNames:(NSArray *)names contexts:(NSArray *)contexts
class func reloadRootControllersWithNames(_ names: [AnyObject]!, contexts contexts: [AnyObject]!)
If you have a object you want to pass from one to the other, you set that object as the context for each page:
NSArray * namesArray = @[@"Page 1", @"Page 2", @"Page 3"]; NSArray * contextsArray = @[myObject, myObject, myObject]; [self reloadRootControllersWithNames:namesArray contexts:contextsArray];
Somewhat counter-intuitively from the method name, while this method is called
reloadRootControllersWithNames:, the WatchKit documentation on Managing Page-Based Navigation indicates that this same method should be used to seed these values at launch time, as well as any time you want to reload this data at runtime.