推动interfaceController时获取WKInterfaceController参考 [英] Get WKInterfaceController reference while pushing interfaceController
问题描述
我在Apple Watch中有一个仪表板控制器,我正在导航到下一个 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的任务.实际上,您需要向后发送数据(向前发送数据就可以了).根据当前的实现,我看到了两种解决任务的方法:
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屋!