ghazi_jaffary ghazi_jaffary - 1 year ago 101
Swift Question

Get WKInterfaceController reference while pushing interfaceController

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?

Answer Source

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download