Schulung_iOS/ListView.swift
2025-10-23 13:45:41 +02:00

45 lines
1.4 KiB
Swift

import SwiftUI
struct ListView: TabContent {
static var title = "List"
static var image = "list.bullet"
static var id = UUID()
@State var bikes = Bike.all
@FocusState var focusedField: UUID? // 1
var body: some View {
List {
Section {
ForEach($bikes) { $bike in
// HStack {
// TextField("New Bike", text: $bike.name)
// .focused($focusedField, equals: bike.id)
// .textFieldStyle(.roundedBorder)
// Spacer()
// Text("\(bike.price, specifier: "%.2f")")
// ColorPicker("", selection: $bike.color)
// }
HStack {
BikeView(bike: bike)
Spacer()
ColorPicker("", selection: $bike.color)
}
}
.onDelete { bikes.remove(atOffsets: $0) }
} footer: {
Button("Add a new Bike") {
let bike = Bike(name: "", color: .white)
bikes.append(bike)
// focusedField = bike.id
}
.frame(maxWidth: .infinity, alignment: .center)
}
}
}
}
#Preview {
ListView()
}