Search code examples
swiftwatchkitapple-watch

interface does not define view controller class


I'm trying to make a workout app following this WWDC video from apple, unfortunately some of the methods are already deprecated in WatchOS 4 and I can't make the code work. every time I click one of the buttons to start the workout the screen goes black and I get the error Extension[11692:537762] [default] -[SPApplicationDelegate companionConnection:reloadRootInterfaceViewControllersWithNames:initializationContextIDs:pageIndex:verticalPaging:]:1432: Error - interface does not define view controller class 'WorkoutInterfaceController'

the second view controller "WorkoutInterfaceController" is in the storyboard and linked to its class.

my WKInterfaceController class:

class InterfaceController: WKInterfaceController {

@IBOutlet var outdoorBtn: WKInterfaceButton!
@IBOutlet var indoorBtn: WKInterfaceButton!

override func awake(withContext context: Any?) {
    super.awake(withContext: context)

    // Configure interface objects here.
}



override func willActivate() {
    // This method is called when watch view controller is about to be visible to user
    super.willActivate()
}

override func didDeactivate() {
    // This method is called when watch view controller is no longer visible
    super.didDeactivate()
}

@IBAction func didTapOutdoorButton() {
    let workoutConfiguration = HKWorkoutConfiguration()
    workoutConfiguration.activityType = .walking
    workoutConfiguration.locationType = .outdoor


    // Pass configuration to next interface controller
    WKInterfaceController.reloadRootPageControllers(withNames: ["WorkoutInterfaceController"], contexts: [workoutConfiguration], orientation: .horizontal, pageIndex: 0)
}

@IBAction func didTapIndoorSaButton() {
    let workoutConfiguration = HKWorkoutConfiguration()
    workoutConfiguration.activityType = .walking
    workoutConfiguration.locationType = .indoor

    // Pass configuration to next interface controller
    WKInterfaceController.reloadRootPageControllers(withNames: ["WorkoutInterfaceController"], contexts: [workoutConfiguration], orientation: .horizontal, pageIndex: 0)
}
}

I would really appreciate the help!


Solution

  • The view controller is missing the identifier in the storyboard