Get WKInterfaceController reference while pushing interfaceController

孤街醉人 提交于 2019-12-12 18:11:17

问题


I have a Dashboard Controller in Apple watch and I am navigating to next WKInterfaceController without using Segue.

pushControllerWithName("Messages_Detail",context: ["Data": messageDetailData])

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?


回答1:


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. 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.


来源:https://stackoverflow.com/questions/33820903/get-wkinterfacecontroller-reference-while-pushing-interfacecontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!