0

I have a List with some rows and some Buttons. I want to play different sounds for each button.

struct ContentView: View  {
let rows = Row.all()

var body: some View {
    List {
    
        ForEach(rows) { row in
            HStack(alignment: .bottom) {
                ForEach(row.cells) { cell in
                    Button(
                        Image(cell.imageURL)
                            .resizable()
                            .scaledToFit()
                        )
                        .onTapGesture {
                            //playAudioAsset(cell.imageURL + "Sound")
                            print(cell.imageURL)
                        }
                }
                    .buttonStyle(PlainButtonStyle())
                    }
                }
            }.padding(EdgeInsets.init(top: 0, leading: -20, bottom: 0, trailing: -20))
        }
        }

Even this simple printdoesn't work. :(

E_net4
  • 27,810
  • 13
  • 101
  • 139
Chris L
  • 87
  • 10

1 Answers1

1

a Button does not need a .onTapGesture, it is included in a button. Read-up on how to use a Button, and try this instead:

Button(action: {
    //playAudioAsset(cell.imageURL + "Sound")
    print(cell.imageURL)
}){
    Image(cell.imageURL)
        .resizable()
        .scaledToFit()
}