List
Table equivalent of UIKit in swiftUI
List(viewModel.pokemons, id: \.id) { pokemon in
}
Grids
Recently introduced in iOS 16.
More robust and available easily.
Detect Taps
Use onTapGesture
.onTapGesture {
print("Tapped cell") // This triggers when you tap anywhere in the cell
}
or use a button wrapped inside the view
VStack {
Button(action: {
print("Tapped")
}) {
Text("Hello world")
}
}
SO | detect taps on a List cell row in SwiftUI
Use contentShape
to get full tappable area option and you may also need to add Spacer()
in between List Cell HStack | VStack
component in order to get the whole cell from left / right accessory view to be tappable. Since by default SwiftUI isn't fully tappable on instances.
.contentShape(Rectangle())