基于页面的“reloadRootControllersWithNames:”在发射循环? [英] Page Based "reloadRootControllersWithNames:" on launch loop?

查看:169
本文介绍了基于页面的“reloadRootControllersWithNames:”在发射循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

遵循Apple的指引

调用此方法重新加载应用程序基于页面的界面中的页面。在启动时,您可以使用此方法自定义要显示的页面集。

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.

在启动时,仅导致循环。每次重新加载调用awakeWithContext或将一次又一次地激活或初始化。

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?

推荐答案

这是WatchKit应用程序的常见问题,因为我们不再有 UIApplicationDelegate 来处理这样的设置。一个好的方法是按如下方式构造代码:

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 (故事板中的主要链接点在这里)

  • PageOneInterfaceController - 您在页面集中显示的第一个界面

  • PageTwoInterfaceController - 页面集中的第二个界面

  • 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

MainInterfaceController 将永远不会显示。您将始终启动到另一组接口控制器,具体取决于 MainInterfaceController.awakeWithContent()中的配套iOS应用程序的缓存状态。这样,您使用 MainInterfaceController ,就像我们在iOS中使用 UIApplicationDelegate 来设置窗口一样根视图控制器。

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.

这篇关于基于页面的“reloadRootControllersWithNames:”在发射循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆