基于页面的“reloadRootControllersWithNames:"在启动循环上? [英] Page Based "reloadRootControllersWithNames:" on launch loop?

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

问题描述

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

遵循 Apple 的准则

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.

在启动时,只会导致循环.每次重新加载时都会调用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 应用程序的缓存状态,您将始终启动到一组不同的界面控制器.通过这种方式,您可以像我们在 iOS 中使用 UIApplicationDelegate 一样使用 MainInterfaceController 来设置窗口和根视图控制器.

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天全站免登陆