I need a multiple rows edit option for SwiftUI list
- My login screen in NavigationView
- After login Home screen is tab bar
- one of the tab is list view (I need edit option for this list)
Here is my total code
first screen I have only simple navigation view with text fields and button.
struct HomeView: View {
@ObservedObject var viewModel = HomeViewModel()
//@State var title = "Home"
var body: some View {
TabView(selection: $viewModel.selectedView) {
TasksView()
.tabItem {
Image(“one”)
Text(“one”)
}.tag(0)
DashboardView()
.tabItem {
Image(“two”)
Text(“two”)
}.tag(1)
NotifcationsView()
.tabItem {
Image(“some”)
Text(“some”)
}.tag(2)
SettingsView()
.tabItem {
Image(“set”)
Text("Se")
}.tag(3)
}
.navigationBarBackButtonHidden(true)
.navigationBarItems(trailing: EditButton())
.navigationBarTitle(Text(viewModel.title) , displayMode: .inline)
}
}
struct TasksView: View {
@ObservedObject var viewModel = TViewModel()
@State var segmentSelection = 0
@State var selection = Set<String>()
// @State var editMode = EditMode.active
var body: some View {
VStack {
Picker(selection: $viewModel.segmentSelection, label: Text("")) {
ForEach(0..<self.viewModel.segments.count) {index in
Text(self.viewModel.segments[index]).tag(index)
}
}.pickerStyle(SegmentedPickerStyle())
.padding(5)
//MyTaskListView()
List (selection: $selection) {
ForEach(viewModel.mt){ t in
//TaskCell(t : task)
Text("Title")
}
.onDelete(perform: viewModel.delete)
}
}.onAppear{
self.viewModel.requestMYTasks()
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
}
init() {
UISegmentedControl.appearance().selectedSegmentTintColor = Colors.navBarColor
UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: UIColor.white], for: .selected)
UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: Colors.navBarColor], for: .normal)
}
}
after keeping simple row also , edit is not working