3

I have created simple List, but I want to hide empty rows. Any help? I know how to hide them for UITableView but not for new SwiftUI List. I tried documentation, but I didn't find anything.

struct LandmarkList: View {
    @EnvironmentObject var userData: UserData

    var body: some View {
        NavigationView {
            List {
                Toggle(isOn: $userData.showFavoritesOnly) {
                    Text("Favorites only")
                }
                ForEach(userData.landmarks) { landmark in
                    if !self.userData.showFavoritesOnly || landmark.isFavorite {
                        NavigationButton(destination: LandmarkDetail(landmark: landmark)) {
                            LandmarkRow(landmark: landmark)
                        }
                    }
                }
            }
            .navigationBarTitle(Text("Landmarks"), displayMode: .large)
        }
    }
}

Result

Result

Lifeplus
  • 531
  • 2
  • 9
  • 22
  • Can you show your code? – Fogmeister Jun 13 '19 at 12:44
  • 2
    Possible duplicate of [How to remove "row" separators from a List in SwiftUI?](https://stackoverflow.com/questions/56489099/how-to-remove-row-separators-from-a-list-in-swiftui) – Matteo Pacini Jun 13 '19 at 12:45
  • Possible duplicate of [Remove extra separators below List in SwiftUI](https://stackoverflow.com/questions/56498045/remove-extra-separators-below-list-in-swiftui) – M Reza Jun 13 '19 at 15:00

2 Answers2

1

Not exactly a solution to this problem but one way of getting rid of the lines in the list is by using the modifier

List{
// Different Views 
}.listStyle(.grouped)
sachin jeph
  • 209
  • 2
  • 4
1

Probably best solution for now is to create ScrollView and create rows with ForEach in it.

Lifeplus
  • 531
  • 2
  • 9
  • 22