[英]navigationBarItems “Type [view] cannot conform to 'View'; only struct/enum/class types can conform to protocols”
I'm trying to apply some navigationBarItems to my View and I've gotten this error - Type '() -> Text' cannot conform to 'View'; only struct/enum/class types can conform to protocols
我正在尝试将一些 navigationBarItems 应用到我的视图中,但我收到了这个错误 -
Type '() -> Text' cannot conform to 'View'; only struct/enum/class types can conform to protocols
Type '() -> Text' cannot conform to 'View'; only struct/enum/class types can conform to protocols
I've been able to dumb the code down to this.我已经能够将代码简化为这一点。 Anyone know what could be causing it?
有谁知道可能是什么原因造成的?
struct NewEntry: View {
var body: some View {
NavigationView {
VStack {
Text("Hello World")
}
.navigationBarItems(trailing: {
Text("Hello World")
})
}
}
}
.navigationBarItems(trailing:)
takes a View
. .navigationBarItems(trailing:)
需要一个View
。
You are providing the View
inside {}
您在
{}
内提供View
.navigationBarItems(trailing: {
Text("Hello World")
})
.navigationBarItems(trailing: Text("Hello, World"))
SwiftUI
's compiler is a bit dumb, small syntax mistakes causes it to throw weird errors at weird places. SwiftUI
的编译器有点笨,小的语法错误会导致它在奇怪的地方抛出奇怪的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.