接口没有定义视图控制器类

时间:2018-06-05 23:33:14

标签: swift watchkit apple-watch

我正在尝试按照WWDC video from apple制作锻炼应用, 遗憾的是,一些方法已经在WatchOS 4中弃用了,我无法使代码工作。每当我点击其中一个按钮开始锻炼时,屏幕变黑,我收到错误Extension[11692:537762] [default] -[SPApplicationDelegate companionConnection:reloadRootInterfaceViewControllersWithNames:initializationContextIDs:pageIndex:verticalPaging:]:1432: Error - interface does not define view controller class 'WorkoutInterfaceController'

第二个视图控制器“WorkoutInterfaceController”位于故事板中并链接到其类。

我的WKInterfaceController类:

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)
}
}

我真的很感激帮助!

2 个答案:

答案 0 :(得分:0)

视图控制器缺少故事板中的标识符

答案 1 :(得分:0)

此外, withNames 列表表示接口控制器标识符而不是接口控制器类名称的列表。 请看图片: enter image description here

WKInterfaceController.reloadRootPageControllers(withNames: ["WizardPage2"], contexts: nil, orientation: .horizontal, pageIndex: 0)