我想在选择器的onChange事件中获取用户选择的索引。
下面是我的代码:
Picker("Username", selection: $selectedOption) {
ForEach(options, id: \.self) {
Text($0)
}
}
.id(UUID())
.pickerStyle(.menu)
.onChange(of: selectedOption) { newValue in
print("Username:", selectedOption + " " + index) <---- Error here
}
怎么拿到索引?!
1条答案
按热度按时间1bqhqjot1#
求索引