when I click onTapGesture event to setup
self.showDetailView = true
self.count = 5
the sheet will popup, but the self.count always be 0
, not be
5
.
so the code Text("5555")
will never be hitt.
it seems state variable count lost what it stored.
import SwiftUI
struct ContentView: View {
@State var showDetailView = false
@State var count = 0
var testArr = [1,2,3,4,5]
var body: some View {
NavigationView {
List(testArr.indices){ indice in
Text("row num (indice)")
.onTapGesture{
self.showDetailView = true
self.count = 5
}
}
.sheet(isPresented: self.$showDetailView) {
if self.count == 0{
// print("count = 0")
}
if self.count == 5{
Text("5555")
}
}
.navigationBarTitle("Your Reading")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…