Search code examples
swiftuiswiftui-listswiftui-navigationlink

In SwiftUI, how to remove list row separator when using list plus NavigatoinLink?


If my list has no NavigationLink, it works well for hiding the list row separator

List {
   ForEach(listVM.tasks, id: \.id) { task in
       TaskListItemView()
           .listRowSeparator(.hidden)
   }
}
.listStyle(.plain)

However, if I add NavigationLink to the item:

List {
   ForEach(listVM.tasks, id: \.id) { task in
       NavigationLink(destination: TaskDetailView()) {
           TaskListItemView()
               .listRowSeparator(.hidden)
       }
   }
}
.listStyle(.plain)

The list row separator lines come up again and cannot be removed.

How to remove them in this case?


Solution

  • you have to put it down a notch like this:

    List {
               ForEach(listVM.tasks, id: \.id) { task in
                   NavigationLink(destination: TaskDetailView()) {
                       TaskListItemView()
                   }
                   .listRowSeparator(.hidden)
               }
            }
            .listStyle(.plain)