我想基于Picker
选定的值在应用程序中显示某种形式。但是,当我足够快地使用分段控件进行切换时(这里似乎是强制的,但是当表单更复杂时,它就非常明显)。编辑:这似乎发生在所有View
上,而不仅仅是表格。
import SwiftUI
struct ContentView: View {
@State private var calculationType = CalculationType.months
@State private var balanceOwned: String = ""
var body: some View {
VStack {
Picker("Calculation Type", selection: $calculationType) {
ForEach(CalculationType.allCases, id: \.self) {
Text($0.rawValue.capitalized)
}
}.pickerStyle(SegmentedPickerStyle())
// This check seems to be the cause of the problem!
if calculationType == .months {
CustomForm(balanceOwned: $balanceOwned)
} else if calculationType == .fixed {
CustomForm(balanceOwned: $balanceOwned)
} else {
CustomForm(balanceOwned: $balanceOwned)
}
}
}
}
struct CustomForm: View {
@Binding var balanceOwned: String
var body: some View {
Form {
Section {
TextField("Test", text: $balanceOwned)
.foregroundColor(.white)
}
}
}
}
enum CalculationType: String, CaseIterable {
case months
case fixed
case minimum
}
表格中的所有内容都会闪烁。我该如何解决?