Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

List rows with buttons onTapGesture

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. 🙁

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()
}
                    
           
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading