UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 42 - Moonshot - Why is adding a navigation bar item changing the list style.

Forums > 100 Days of SwiftUI

For the part 3 challenge, I'm adding a navigaiton bar item to toggle between showing mission dates and the crew name. As soon as I add the trailing item, the style of the table view is changed from the default plain style to some other style that doesnt seem to match any other one (like grouped, inset grouped etc)

I am using Xcode 12 beta 6 so I dont know if that could be the cause.

Before adding a navigation bar item

Before image

struct ContentView: View {
    let astronauts: [Astronaut] = Bundle.main.decode(file: "astronauts.json")
    let missions: [Mission] = Bundle.main.decode(file: "missions.json")

    var body: some View {
        NavigationView {
            List(missions) { mission in
                NavigationLink(destination: MissionView(mission: mission)) {
                    MissionRowView(mission: mission)
                }
            }
            .navigationBarTitle("Moonshot")
        }
    }
}

After adding a navigation bar item

After image

struct ContentView: View {
    let astronauts: [Astronaut] = Bundle.main.decode(file: "astronauts.json")
    let missions: [Mission] = Bundle.main.decode(file: "missions.json")

    @State var showCrew = false

    var body: some View {
        NavigationView {
            List(missions) { mission in
                NavigationLink(destination: MissionView(mission: mission)) {
                    MissionRowView(mission: mission, showCrew: showCrew)
                }
            }
            .navigationBarTitle("Moonshot")
            .navigationBarItems(trailing: Button("Toggle", action: { showCrew.toggle() }))
        }
    }
}

Adding in .listStyle(PlainListStyle()) after the List fixes it but it seems like it shouldnt be neede in the first place.

2      

It might have to do with your MissionRowView. Could you share the code?

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.