I am trying to use a list selection for the user to zero or more days from a list. I have tried to use the solution listed in this question, but to no avail.
My code is given below, and I have verified edit mode is active. I should expect behaviour like in the answer linked to above.
Code:
struct EditView: View {
@State var selectKeeper = Set<String>()
var weekdays: [String] = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
@Environment(\.editMode) var mode
var body: some View {
Form {
Section(header: Text("Overtime Days")) {
List(self.weekdays, id: \.self, selection: $selectKeeper) { day in
Text(day)
}
}
} .navigationBarTitle(Text("My Title"))
.padding(.top)
.onAppear(perform: {
print(self.mode?.value as Any)
})
}
}
The EditButton is contained in a parent view and is enabled in the following piece of code.
struct JobDetailHost: View {
@Environment(\.editMode) var mode
@Binding var jobDetails: JobDetails
var body: some View {
VStack {
if self.mode?.value == .inactive {
JobDetailView(jobDetails: jobDetails)
} else {
EditView(jobDetails: $jobDetails)
.onDisappear(perform: {
//DO STUFF...
})
}
}
.navigationBarItems(trailing: EditButton())
.onAppear(perform: bindDraft)
}
}
The table should show the selection behaviour as in the other answer, but currently it displays as just a normal list in edit mode.