I have a WKInterfaceController for a watchkit app, InterfaceController.m. It creates paginated content like this:
- (void)willActivate {
[super willActivate];
NSDate *now = [[NSDate alloc] init];
NSDictionary *time = @{@"time":[NSString stringWithFormat:@"%f",[now timeIntervalSince1970]]};
NSArray *contexts = [[NSArray alloc] initWithObjects:time,time,nil];
NSArray *names = [[NSArray alloc] initWithObjects:@"page",@"page",nil];
[WKInterfaceController reloadRootControllersWithNames:names contexts:contexts];
}
The WKInterfaceController with "page" as the identifier is called PageInterfaceController.m and just displays the time sent by InterfaceController.m
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
[label setText:[context objectForKey:@"time"]];
}
This works great the first time it's loaded, but after exiting and relaunching the app, it shows the old times. How can I get the app to go back to InterfaceController.m and update the times?
Yes, I know I could just put the time in PageInterfaceController, but in my real app, the InterfaceController is getting location data and sending it to the pages, even determining the number of pages to be created.
You can download the whole sample project here:
awakeWithContext will not be called a second time if the watch keeps the controller loaded, which is probably why it doesn't get updated after the initial load.
Instead, use viewWillActivate in your PageInterfaceController just like you do in your main InterfaceController, like this: