Swift 接口未定义视图控制器类
我正试着制作一个健身应用程序, 不幸的是,有些方法在WatchOS 4中已经被弃用,我无法使代码正常工作。每次我单击其中一个按钮开始训练时,屏幕变黑,出现错误Swift 接口未定义视图控制器类,swift,watchkit,apple-watch,Swift,Watchkit,Apple Watch,我正试着制作一个健身应用程序, 不幸的是,有些方法在WatchOS 4中已经被弃用,我无法使代码正常工作。每次我单击其中一个按钮开始训练时,屏幕变黑,出现错误扩展[11692:537762][default]-[SPApplicationDelegate CompanyConnection:ReloadRootInterfaceDeviceController WithNames:InitializationContextId:pageIndex:verticalPaging:]:1432:错误
扩展[11692:537762][default]-[SPApplicationDelegate CompanyConnection:ReloadRootInterfaceDeviceController WithNames:InitializationContextId:pageIndex:verticalPaging:]:1432:错误-接口未定义视图控制器类“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)
}
}
我真的很感激你的帮助 视图控制器缺少情节提要中的标识符此外,带有名称的列表表示接口控制器的标识符列表,而不是接口控制器类名。 请看图片:
WKInterfaceController.reloadRootPageControllers(withNames: ["WizardPage2"], contexts: nil, orientation: .horizontal, pageIndex: 0)