Post

Replies

Boosts

Views

Created

SwiftUI List rows with multiple buttons trigger all buttons
I have a SwiftUI List with an HStack containing two Buttons. If I tap either button, or elsewhere in the cell, the entire cell highlights and actions for both Buttons are fired off. I can't find where this is documented, but have found that adding .buttonStyle(BorderlessButtonStyle()) to the List prevents this behavior - tapping individual buttons fire their individual actions as expected. Is this an expected behavior? Below is my example without the workaround applied: struct ContentView: View {     var body: some View {         List {             HStack {                 Button(action: {                     print("button 1 tapped")                 }) {                     Text("One")                 }                 Button(action: {                     print("button 2 tapped")                 }) {                     Text("Two")                 }             }         }     } } Thanks!
3
1
3.6k
Jun ’20