推送 interfaceController 时获取 WKInterfaceController 引用 [英] Get WKInterfaceController reference while pushing interfaceController
问题描述
我在 Apple watch 中有一个 Dashboard Controller,我导航到下一个 WKInterfaceController 而不使用 Segue.
I have a Dashboard Controller in Apple watch and I am navigating to next WKInterfaceController without using Segue.
pushControllerWithName("Messages_Detail",context: ["Data": messageDetailData])
现在我需要在加载数据后将数据从 仪表板 传递到 Messages_Detail.我在仪表板中没有任何参考.如何将数据传递给它?
Now I need to pass data from Dashboard to Messages_Detail later on after it has been loaded. I don't have any reference of it in Dashboard. How can I pass data to it?
推荐答案
这里你有一个在控制器之间传递数据的常规任务,一般来说它不是一个特定于 Watch 的任务.实际上,您需要将数据发回(通过向前发送数据,您已经可以了).根据当前的实现,我看到了 2 种方法来解决您的任务:
Here you have a regular task of passing data between controllers and it is not a Watch-specific task generally speaking. Actually you need to send data back (with sending data forward you're already OK). I see 2 ways to solve your task depending on the current implementation:
- 使用
Messages_Detail
控制器作为Dashboard
的代表.您还应该定义一些协议来描述Messages_Detail
的哪些方法可以在委托上下文中调用. - 使用
NSNotificationCenter
或发布/订阅模式的任何其他实现来提供应用不同部分的通信.在这种情况下,您的Dashboard
将发布通知,Messages_Detail
控制器将观察这些通知.
- Use the
Messages_Detail
controller as a delegate of theDashboard
one. You also should define some protocol that will describe which methods of theMessages_Detail
are available to call in a delegate context. - Use
NSNotificationCenter
or any other implementation of a Pub/Sub pattern to provide communication of different parts of your app. In this case yourDashboard
will post notifications which theMessages_Detail
controller will observe.
这篇关于推送 interfaceController 时获取 WKInterfaceController 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!