1

I try to add and remove sections in the list by using binding value, so when add or remove items form the "listSectins" that will add and remove sections in the list.

   @State private var listSectins = ["SectionOne", "SectionTwo"]
    
     var body: some View {
            
            NavigationView {
                    List(selection: $selection) {
                            Section {
                            ForEach(self.firstSectionData) { rowData in
                                MainMenuRowView(rowData: rowData)
                            }
                            .onMove(perform: { indices, newOffset in
                                self.groupData.rowsGroup[0].move(fromOffsets: indices, toOffset: newOffset)
                            })
                        }
                        .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
        }
    }
1
  • Would you show your demo code? It is not clear what activates binding and what is going to be inside sections, etc. Commented Dec 4, 2020 at 12:44

1 Answer 1

1

I try the code bellow and its work

 List(selection: $selection) {
            if self.isEditMode {
                Section {
                    ForEach(self.firstSectionData) { rowData in
                        MainMenuRowView(rowData: rowData, isEditMode: self.isEditMode)
                    }
                    .onMove(perform: { indices, newOffset in
                        self.groupData.rowsGroup[0].move(fromOffsets: indices, toOffset: newOffset)
                    })
                }
                .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16))
            }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.