Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

ios - Page Based "reloadRootControllersWithNames:" on launch loop?

- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
    [WKInterfaceController reloadRootControllersWithNames:@[@"pageOne", @"pageTwo"] contexts:nil];
}

Following Apple's guidelines

Call this method to reload the pages in your app’s page-based interface. At launch time, you use this method to customize the set of pages you want displayed.

at launch time, only results in a loop. With each reload calling awakeWithContext or will Activate or init again and again.

Is there a better way to go about reloading the Page-Based app on launch with a loop occurring?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a common problem with WatchKit apps since we no longer have a UIApplicationDelegate to handle such set up. A good approach would be to structure your code as follows:

  • MainInterfaceController (the main link in storyboard points here)
  • PageOneInterfaceController - your first interface to display in the page set
  • PageTwoInterfaceController - your second interface in the page set

The MainInterfaceController will never actually get displayed. You will always launch into a different set of interface controllers depending on the cached state of the companion iOS App in MainInterfaceController.awakeWithContent(). This way, you use the MainInterfaceController in a similar manner that we use the UIApplicationDelegate in iOS to set up the window and root view controller.

I have used this approach in an app that had many different page sets to choose from and it worked very well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...