struct ContentView: View {
@State private var showingAlertSetup = false
var body : some View {
alertsView
}
@ViewBuilder // <--- here
private var alertsView: some View {
NavigationStack { // <--- here
Form {
HStack(spacing: 20) {
Button(action: {
showingAlertSetup = true
}) {
HStack {
Image(systemName: "plus")
Text("Add New Alert")
}
.padding()
.foregroundColor(.blue)
}
Spacer()
Button(action: {
// Action for adding a recurring alert
}) {
HStack {
Image(systemName: "plus")
Text("Add Recurring Alert")
}
.padding()
.foregroundColor(.blue)
}
}
.padding(.vertical, 8)
.listRowBackground(Color.clear) // <--- here
Section(header: Text("Active Alerts")) {
Text("alertSettings") // <--- for my testing
// ForEach(alertSettings) { alert in
// alertRow(for: alert)
// }
// .onDelete(perform: deleteAlert)
// .listRowSeparator(.hidden)
}
.listRowBackground(Color.clear) // <--- here
}
.listStyle(PlainListStyle())
.navigationTitle("Alerts")
}
}
func deleteAlert(at offsets: IndexSet) {
// offsets.forEach { alertSettings.remove(at: $0) }
}
}
注意,debe debe duals使用
NavigationView
代替。
您需要2个修饰符:
。listrowinsets(.init())
为:
NavigationStack