SwiftUI - 选取器不更新



我有一个小问题,

我有一个带有选择器的Swift应用程序:

/// DATA.swift
import SwiftUI
class FormPage: ObservableObject { 
@State var country = ["USA", "Japan", "Germany"]
@State var index = 0
}
/// FORM.swift
import SwiftUI
struct ContentView: View {

@StateObject var choiceForm = FormForFormulaire()

var body: some View {

Form {
Section {
Picker(selection: $choiceForm.index, label: Text("Pays de destination")) {
ForEach(0 ..< choice.country.count) {
Text(choiceForm.country[$0]).tag($0)
}
}
}
}

选取器视图正在工作,但没有更新:我单击"日本",视图没有更改。

对不起我的英语,我希望有人能理解我!!

感谢

使用@Published作为FormPage类内的索引

@Published var index = 0

最新更新