接口没有定义视图控制器 class
interface does not define view controller class
我正在尝试根据此 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" 在故事板中并链接到它的 class。
我的 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)
}
}
非常感谢您的帮助!
视图控制器缺少情节提要中的标识符
此外,withNames 列表表示接口控制器的标识符列表,而不是接口控制器 class 名称。
请看图片:
WKInterfaceController.reloadRootPageControllers(withNames: ["WizardPage2"], contexts: nil, orientation: .horizontal, pageIndex: 0)
我正在尝试根据此 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" 在故事板中并链接到它的 class。
我的 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)
}
}
非常感谢您的帮助!
视图控制器缺少情节提要中的标识符
此外,withNames 列表表示接口控制器的标识符列表,而不是接口控制器 class 名称。
请看图片:
WKInterfaceController.reloadRootPageControllers(withNames: ["WizardPage2"], contexts: nil, orientation: .horizontal, pageIndex: 0)