获取使用 presentControllerWithNames:contexts 创建的 WatchKit 接口控制器实例:

Get WatchKit interface controller instances created with presentControllerWithNames:contexts:

我正在使用 [self presentControllerWithNames:self.controllerNames contexts:self.controllerContexts]; 呈现基于页面的模态,其中 controllerNames 只是 NSStringNSArray,其中包含我的界面控制器名称。问题是我想访问创建的控制器。

文档说

WatchKit loads and initializes the new interface controllers and animates them into position on top of the current interface controller.

但我想引用它们,以便从外部调用 becomeCurrentPage 方法。

所以,我希望能够在列表中创建这些控制器后保存它们,并使用 [self.controllers[2] becomeCurrentPage].

之类的东西以编程方式更改页面

因为您可以在呈现界面控制器时提供上下文,所以您可以传递对 self 的引用。这样,您就可以建立从呈现的控制器到其父控制器的引用。一旦存在这种关系,您就可以使用委托模式等方式进行通信。

我在我自己的 Watch 应用程序中广泛使用了它,并且我在我的 JBInterfaceController subclass on GitHub.

中包含了很多这些机制