问题
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_Detailcontroller as a delegate of theDashboardone. You also should define some protocol that will describe which methods of theMessages_Detailare available to call in a delegate context. - Use
NSNotificationCenteror any other implementation of a Pub/Sub pattern to provide communication of different parts of your app. In this case yourDashboardwill post notifications which theMessages_Detailcontroller will observe.
来源:https://stackoverflow.com/questions/33820903/get-wkinterfacecontroller-reference-while-pushing-interfacecontroller