SwiftUI List - Enable Multiselection only on ONE section of List

Viewed 9

Goal:

  1. Have two lists on one screen.

List 1:Should have multiple selections and reorder capability.

List 2:- My Lists: Should have Delete and reorder capabilty

Problem: If i create 1 list with selections enabled, then it automatically applies this to all the sections of the list.

Code:

            ZStack{    
                VStack {
                    //selection adds a checkmark to the list
                    List(selection:$categoryCollection.selectedCategories){
                         Section{
                                ForEach(categoryCollection.categories, id: \.self) { category in
                                    
                                    CategoryListItem(name: category.name, icon: category.icon)
                                }
                              }
                            }
                        }
                        
                        Section(header: Text("My lists"))
                        {
                            ForEach( todoListCollection.todoLists){ list in
                                TodoListRowView(todoList: list)
                 
                            }
//THIS IS BEING OVERRIDEN BY SELECTION 
                            .onDelete{
                                todoListCollection.removeList(indexSet: $0)
                                print("list removed")
                                
                            }
                            .onMove {
                                todoListCollection.moveList(from: $0, to: $1)
                                print("list moved")
                            }
                            
                            
                        }.headerProminence(.increased)
                        
                    }//list
                    .listStyle(InsetGroupedListStyle())
                    
                    .toolbar {
                        EditButton()
                    }
                    Spacer()
                    
                    Footer()
                    
                    
                    
                }
                //VStack
                
                .environment(\.editMode, $editMode)
                .searchable(text: $queryString)
                .searchable(text: $queryString,placement: .navigationBarDrawer(displayMode: .always))
            }
        }//navigationView

enter image description here

0 Answers
Related