是否可以在SwiftUI的子视图中显示工作表,而其父视图中已经有工作表?
struct SheetTest: View {
@State var showFirstSheet = false
var body: some View {
VStack {
Text("FirstView")
.onTapGesture(count: 1, perform: {
showFirstSheet = true
})
SomeView()
}
.sheet(isPresented: $showFirstSheet, content: {
Text("firstsheet")
})
}
}
struct SomeView:View {
@State var showSecondSheet = false
var body: some View {
Text("SecondView")
.onTapGesture(count: 1, perform: {
showSecondSheet = true
})
.sheet(isPresented: $showSecondSheet, content: {
Text("secondsheet")
})
}
}
我当前正在使用Xcode 12 beta 3! 第二张纸不能这样显示! 我必须在父视图中显示它!
答案 0 :(得分:0)
解决方案是注意不要将.sheet
添加到同一视图树中。
我正在使用Xcode 12.1 (12A7403)
。
struct SheetTest: View {
@State var showFirstSheet = false
var body: some View {
VStack {
Text("FirstView")
.onTapGesture(count: 1, perform: {
showFirstSheet = true
})
.sheet(isPresented: $showFirstSheet, content: {
Text("firstsheet")
})
SomeView()
}
}
}
struct SomeView:View {
@State var showSecondSheet = false
var body: some View {
Text("SecondView")
.onTapGesture(count: 1, perform: {
showSecondSheet = true
})
.sheet(isPresented: $showSecondSheet, content: {
Text("secondsheet")
})
}
}