Може да се постигне по този начин,
Представете InterfaceController в pageNavigation с подходящи контекстни стойности,
[self presentControllerWithNames:@[@"TestInterfaceController",@"TestInterfaceController",@"TestInterfaceController"] contexts:@[@"Page 1",@"Page 2",@"Page 3"]];
След това създайте свойство NSString за проследяване на страницата и етикет за показването й,
@property (nonatomic, strong) NSString *currentContext;
@property (weak, nonatomic) IBOutlet WKInterfaceLabel *pageLabel;
В awakeWithContext го присвоете на свойството NSString,
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
NSLog(@"%@",context);
self.currentContext = context;
}
Покажете го на willActive,
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
NSLog(@"%@ willActivate",self.currentContext);
[self.pageLabel setText:self.currentContext];
}
Можете също така да откриете кога страницата е деактивирана,
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
NSLog(@"%@ didDeactivate",self.currentContext);
}
Редактиране: Ако навигациите на страниците са конфигурирани с помощта на Storyboard Segue, тогава заменете този метод в Source IntefaceController от мястото, където сте създали преход на модел към дестинационен контролер, за да предоставите контексти,
- (NSArray *)contextsForSegueWithIdentifier:(NSString *)segueIdentifier {
NSArray *contexts = nil;
if ([segueIdentifier isEqualToString:@"MyPageNavigation"]) {
contexts = @[@"Page 1",@"Page 2",@"Page 3"];
}
return contexts;
}
person
Dhaval Panchal
schedule
22.05.2015