Table
1. 基本用法
import SwiftUI
struct ContentView: View {
let items = ["Item 1", "Item 2", "Item 3", "Item 4"]
var body: some View {
Table(items, id: \.self) {
TableColumn("Items") { item in
Text(item)
}
}
}
}2. 使用模型数据
struct Item: Identifiable {
var id = UUID()
var name: String
var description: String
}
struct ContentView: View {
let items = [
Item(name: "Item 1", description: "Description 1"),
Item(name: "Item 2", description: "Description 2"),
Item(name: "Item 3", description: "Description 3")
]
var body: some View {
Table(items) {
TableColumn("Name", value: \.name)
TableColumn("Description", value: \.description)
}
}
}3. 增加交互功能
4. 表格行的删除功能
5. 自定义行视图
总结
Last updated