【发布时间】:2020-01-05 15:30:14
【问题描述】:
我发现了这个问题 - What is the best way to switch views in SwiftUI? - 但我无法找到适合我的答案。
struct view4x: View {
@State var goView: Bool = false
var body: some View {
if goView {
view5x(goView1: self.$goView)
} else {
Form {
/* ... */
}
}
}
}
并且按钮在表单内:
Button(action: {
self.goView.toggle()
}) {
Text("Catalog")
}
对于我的其他观点,我有:
struct view5x: View {
@Binding var goView1: Bool
var body: some View {
Text("TEST")
Button(action: {
self.goView1.toggle()
}) {
Text("Return")
}
}
}
我只是得到两个主体都声明不透明返回类型的错误。它不预览。
【问题讨论】: