<code>import SwiftUI struct ContentView: View { @State var value = "v1" var values = ["v1","v2","v3"] var body: some View { if #available(iOS 17.0, *) { Picker("", selection: $value) { ForEach(values, id: \.self) { entry in Text(entry) }.onChange(of: value) { oldValue, newValue in print("currentValue: \(value), oldValue: \(oldValue), newValue: \(newValue)") } } } } } </code>

问题描述 投票:0回答:1

Picker

Picker("", selection: $value) {
    ForEach(values, id: \.self) { entry in
        Text(entry)
    }
}
.onChange(of: value) { oldValue, newValue in
    print("currentValue: \(value), oldValue: \(oldValue), newValue: \(newValue)")
}
swift swiftui
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.