情况 1:- 当我在 VStack 中有多个按钮时,单击其中任何一个按钮时,两个按钮的动作处理程序都会立即执行,仅当 VStack 是 List 的子项时才会发生这种情况。例如-
List {
VStack {
Button(action: { print("A") }) {
Text("Button A")
}
Button(action: { print("B") }) {
Text("Button B")
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,当您单击任何一个按钮(例如按钮 B)时,o/p 是:- A B
案例 2 :- 尝试只使用 VStack,它工作正常。例如-
VStack {
Button(action: { print("C") }) {
Text("Button C")
}
Button(action: { print("D") }) {
Text("Button D")
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,当您单击任何一个按钮(例如按钮 D)时,o/p 是:- D
我是 iOS 编程的新手,请帮助我了解我哪里出错了还是 SwiftUI 的问题?