swift - 接口(interface)未定义 View Controller 类

标签 swift watchkit apple-watch

我正在尝试按照此 WWDC video from apple 制作一个锻炼应用程序, 不幸的是,某些方法在 WatchOS 4 中已被弃用,我无法使代码工作。每次我单击其中一个按钮开始锻炼时,屏幕都会变黑,并收到错误 Extension[11692:537762] [default] -[SPApplicationDelegate attendantConnection:reloadRootInterfaceViewControllersWithNames:initializationContextIDs:pageIndex:verticalPaging:]:1432:错误 - 接口(interface)未定义 View Controller 类“WorkoutInterfaceController”

第二个 View Controller “WorkoutInterfaceController”位于 Storyboard中并链接到其类。

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

我非常感谢您的帮助!

最佳答案

View Controller 缺少 Storyboard中的标识符

关于swift - 接口(interface)未定义 View Controller 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50710306/

相关文章:

ios - 尝试为表格设置行数时 WatchKit 应用程序崩溃

api - 通过 REST API 的 Apple HealthKit 数据(2018 年更新)

ios - 有没有办法在 Apple Watch 中制作类似 iPhone 的进度条?

SwiftUI Zstack – 使元素忽略安全区域而另一个不

Swift 类型推断和类型检查问题

ios - Xcode 7.3 : Can't import MetalKit

xcode - 闭包中的 inout 参数使 Swift 编译器崩溃

ios - Apple Watch 应用程序 : run an MKDirectionsRequest through the parent iOS app in the background?

swift - 在 NSUserDefaults 中将多个对象传递给 WatchKit

watchkit - animateWithDuration 缺少完成 block ,WatchOS 2