When User clicks on the List Row, DetailView is shown with more details about the selected Row.
This is done by
● embedding List View inside NavigationView (as highlighted in Yellow)
● embedding each Row inside NavigationLink which calls DetailView with name parameter (as highlighted in Blue)
● we also add navigationBarTitle() for each View to tell us on which Screen we are (as highlighted in Green)
ContentView.swift
import SwiftUI
//==========================================================================
// ContentView
//==========================================================================
struct ContentView : View {
var body : some View {
NavigationView {
List {
NavigationLink("Stanford Dish", destination: DetailView(name: "Details for Stanford Dish"))
NavigationLink("Edgewood" , destination: DetailView(name: "Details for Edgewood" ))
NavigationLink("Mission Peak" , destination: DetailView(name: "Details for Mission Peak" ))
NavigationLink("Big Basin" , destination: DetailView(name: "Details for Big Basin" ))
NavigationLink("Alum Rock" , destination: DetailView(name: "Details for Alum Rock" ))
}.navigationBarTitle("Hiking Trails")
}.navigationViewStyle(StackNavigationViewStyle())
}
}
//==========================================================================
// DetailView
//==========================================================================
struct DetailView : View {
var name: String
var body: some View {
Text(name).navigationBarTitle("Detail View")
}
}
ContentView DetailView