我正在尝试按照此 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/