假设我有一个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