Reputation: 53
I'm following Apple's SwiftUI tutorial and currently stuck on this chapter. I'm trying to add a navigation title and toolbar to this View but it isn't showing up for some reason.
Here's my code:
import SwiftUI
struct ScrumsView: View {
let scrums: [DailyScrum]
var body: some View {
NavigationStack {
List(scrums) { scrum in
NavigationLink(destination: Text(scrum.title)) {
CardView(scrum: scrum)
}
.listRowBackground(scrum.theme.mainColor)
}
.navigationTitle("Daily Scrums")
.toolbar {
Button(action: {}) {
Image(systemName: "plus")
}
}
}
}
}
struct ScrumsView_Previews: PreviewProvider {
static var previews: some View {
ScrumsView(scrums: DailyScrum.sampleData)
}
}
And here's the preview I'm getting:
I'm very new to Swift/SwiftUI and not understanding why this isn't working... any help would be appreciated. Thanks in advance
I saw many other people running into similar issues but they had .navigationTitle
and .toolbar
attached to the NavigationStack
instead of the List
so I have tried moving those two modifiers around but nothing has worked.
Upvotes: 3
Views: 5018
Reputation: 53
Nevermind, I figured it out. It was getting added but just not showing in the preview (misleading because it shows in the preview with the exact same code in the SwiftUI tutorial).
For anyone else who is running into the same issue, you should see it show up if you build and run the code. Alternatively, put the preview in a specific device viewport and it'll show up.
Upvotes: 0