【发布时间】:2020-06-25 18:43:20
【问题描述】:
我有一个使用 SwiftUI 构建的简单 Apple Watch 应用。我正在尝试使用NavigationLink添加一个按钮以从我的ContentView 转到我的SettingsView
struct ContentView: View {
@EnvironmentObject var settings: SettingsObject
@EnvironmentObject var chilly: ChillyObject
var body: some View {
ZStack{
VStack{
Text(chilly.message)
.foregroundColor(chilly.textColor)
.font(.largeTitle)
.fontWeight(.heavy)
.multilineTextAlignment(.center).fixedSize(horizontal: false, vertical: true)
.padding(.top, 9.0)
Text(chilly.emoji)
.font(.largeTitle).foregroundColor(Color.black)
.multilineTextAlignment(.center)
.padding(.bottom, -20.0)
NavigationLink(destination: SettingsView) {
Text("⚙️ Settings")
.font(.body)
.fontWeight(.semibold)
}
.frame(width: 120.0)
}
}
}
}
struct SettingsView: View {
@EnvironmentObject var settings: SettingsObject
var body: some View {
ZStack {
VStack {
Text("Threshold Temp: \(Int(settings.thresholdTemperature))° \(settings.thresholdUnits)")
.fontWeight(.light)
Slider(value: $settings.thresholdTemperature, in: 30...90, step: 1)
.padding([.leading, .bottom, .trailing])
}
}
}
}
我收到此错误:Type 'SettingsView.Type' cannot conform to 'View'; only struct/enum/class types can conform to protocols 在这一行:NavigationLink(destination: SettingsView) { 在我的ContentView 中。
我认为它是在我遵循教程并开始尝试使用 @EnvironmentObject 包装器而不是 @ObservedObject 包装器时引入的,但老实说我不能确定。任何见解都会很棒。谢谢!
【问题讨论】:
-
错字 -
SettingsView()
标签: swift swiftui watchkit watchos