我正在尝试显示一个大数据表(超过100行乘100列)。我将数据保存在二维数组中:
import SwiftUI
struct PivotCell : Hashable {
enum CellType {
case columnHeader, rowHeader, value, total, grandTotal, blank
}
let id = UUID()
let cellType : CellType
let contents : String
static func == (lhs: PivotCell, rhs: PivotCell) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
init(cellType: PivotCell.CellType, contents: String ) {
self.cellType = cellType
self.contents = contents
}
}
struct PivotTableView: View {
var displayData : [[PivotCell]]
var body: some View {
GeometryReader { geometry in
List(self.displayData, id: \.self) { row in
HStack {
ForEach(row, id: \.id) { cell in
PivotCellView(cell)
}
}
}.frame(width: geometry.size.width, height: geometry.size.height).id(UUID())
}
}
}
struct PivotCellView: View {
let cell: PivotCell
var body: some View {
Text(cell.contents)
.frame(width: 100, height: 30, alignment: .center)
}
init(_ cell: PivotCell) {
self.cell = cell
}
}
struct PivotTableView_Previews: PreviewProvider {
static var cell = PivotCell(cellType: .value, contents: "123")
static var displayData = [[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell],
[cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell, cell]]
static var previews: some View {
PivotTableView(displayData: displayData)
}
}
我试图:
有什么办法解决这个问题吗?