推动interfaceController时获取WKInterfaceController参考 [英] Get WKInterfaceController reference while pushing interfaceController

查看:174
本文介绍了推动interfaceController时获取WKInterfaceController参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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:

  1. 使用Messages_Detail控制器作为Dashboard的委托.您还应该定义一些协议,以描述Messages_Detail的哪些方法可在委托上下文中调用.
  2. 使用NSNotificationCenter或发布/订阅模式的任何其他实现来提供应用程序不同部分的通信.在这种情况下,您的Dashboard将发布Messages_Detail控制器将遵守的通知.
  1. Use the Messages_Detail controller as a delegate of the Dashboard one. You also should define some protocol that will describe which methods of the Messages_Detail are available to call in a delegate context.
  2. Use NSNotificationCenter or any other implementation of a Pub/Sub pattern to provide communication of different parts of your app. In this case your Dashboard will post notifications which the Messages_Detail controller will observe.

这篇关于推动interfaceController时获取WKInterfaceController参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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