.navigationBarTitle()
and .navigationBarItem()
are modifiers on the View
inside of the NavigationView
, not on the NavigationView
itself:
struct LandmarkList: View {
var body: some View {
NavigationView {
List(landmarkData) { landmark in
LandmarkRow(landmark: landmark)
}
.navigationBarItem(title: Text("Done"))
.navigationBarTitle(Text("Landmarks"))
}
}
}
and if you think about it, this makes sense. As the View
within the NavigationView
changes, the new View
dictates what the title and contents of the navigation bar should be.