Reputation: 115
I have a List
with some row
s and some Button
s. 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 print
doesn't work. :(
Upvotes: 0
Views: 62
Reputation: 36119
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()
}
Upvotes: 1