iosswift3apple-watchwatchos-3

Trigger segue programmatically on watchOS


I'm working on a watchOS 3 app.

I have a segue hooked up to a button and it is working correctly. Now I want to trigger it programmatically.

Upon receiving a message from the phone, I want to navigate the watch to a specific view, but I can't seem to call self.performSegue method via WatchKit.

Is there any way to do this?


Solution

  • In WatchKit you cannot perform a segue programmatically. Instead you need to use pushController(withName:context:), presentController(withName:context:) or presentController(withNames:contexts:).

    Make sure to set identifiers for your WKInterfaceControllers in InterfaceBuilder.

    If you need to pass data to controllers, have a look at contextForSegue(withIdentifier: String) and contextsForSegue(withIdentifier: String)