假设我有一行List
个按钮和两个按钮,在没有整行高亮显示的情况下,我如何区分哪个按钮被点击?
对于这个示例代码,当点击行中的任何一个按钮时,都会调用这两个按钮的操作回调.
// a simple list with just one row
List {
// both buttons in a HStack so that they appear in a single row
HStack {
Button {
print("button 1 tapped")
} label: {
Text("One")
}
Button {
print("button 2 tapped")
} label: {
Text("Two")
}
}
}
当只有一个按钮被点击一次时,我看到两个按钮都被调用的回调,这不是我想要的:
button 1 tapped
button 2 tapped