问题
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:
- 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.
来源:https://stackoverflow.com/questions/33820903/get-wkinterfacecontroller-reference-while-pushing-interfacecontroller