Hi, I wrote the code below to demonstrate an issue I cannot handle, since I am very new to swiftui
struct Cell: Identifiable {
var id: UUID = UUID()
var i: Int = 0
init(i: Int) {
self.i = i
}
}
struct ContentView: View {
var columns: [GridItem] = [GridItem](repeating: GridItem(.fixed(40), spacing: 5), count: 60)
var cells: [Cell] = []
init() {
cells.removeAll()
for i in 0..<180 {
cells.append(Cell(i:i))
}
}
var body: some View {
ScrollView([.horizontal, .vertical]) {
LazyVGrid(columns: columns, spacing: 5) {
ForEach(cells) { cell in
ButtonView(cell: cell)
}
}
}
}
}
struct ButtonView: View {
var cell: Cell
@State var popOver: Bool = false
var body: some View {
Button {
popOver.toggle()
} label: {
Text("\(cell.i)")
}
.popover(isPresented: $popOver, content: {
Text("Information line of button \(cell.i)").padding()
})
}
}
#Preview {
ContentView()
}
Running the code above, button clicks are not always work