[英]SwiftUI - Picker doesn't update
我有個小問題,
我有一個帶有選擇器的 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
class 內的索引
@Published var index = 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.