Module 4 Challenge 15 - Jumping to another view

Hi…

I have two views - ContentView() and BookReviewView()… Below is from my ContentView()… What is not working is when I click on the “book” under the label of the navigation view, it supposed to jump to BookReviewView() but it doesn’t… BookReviewView() only contains Text() at the moment… I also tried using Button() instead of NavigationLink() but same results…

Please advise… Am I missing anything? Don’t really want to peek on the solution… I want to finish the challenge by myself with a little help…

var body: some View {
    GeometryReader { geo in
        ScrollView {
            LazyVStack (alignment: .leading) {
                Text("My Library")
                    .font(Font.custom("Avenir Heavy", size: 24))
                    .padding(.bottom)
                
                ForEach(bookModel.books) { book in
                    NavigationLink (
                        destination: BookReviewView(),
                        label: {
                            ZStack (alignment: .leading) { ...     }
                            .padding()
                        }) // Navigation Link End
                }
            }
        }
    }
}

}

struct BookReviewView: View {
var body: some View {
VStack {
Text(“Amazing Words”)
.font(Font.custom(“Avenir Heavy”, size: 24))
.padding(.bottom)
Text(“Read Now!”)
.font(Font.custom(“Avenir Heavy”, size: 20))
.padding(.bottom)

        Text("Mark for later!")
            .font(Font.custom("Avenir Heavy", size: 14))
            .padding(.bottom)
        
        Text("Rate Amazing Words")
            .font(Font.custom("Avenir Heavy", size: 15))
            .padding(.bottom)
    }
}

}

@cliffbenedik

Hi Cliff,

When you use a NavigationLink you need to have your overall View code embedded in a NavigationStack otherwise the NavigationLink will not be active.

So wrap your ScrollView { } in a NavigationStack { } ie:

NavigationStack {
    ScrollView {
        // The rest of you code goes here
    }
}

Thanks Chris!

Awesome! Although I think you meant NavigationView{} instead of NavigationStack{}… I can’t compile with NavigationStack{}

Cheers,

Oh, does that mean that you are not using Xcode 14?

1 Like

yes… Still on v13.2.1… On the 14 version, NavigationView{} is replaced by NavigationStack{}?

A Code with Chris vid featuring Flo.

NavigationView is still available in Xcode 14 but it has been deprecated in favour of NavigationStack or NavigationSplitView. It means that in future versions of iOS and Xcode, NavigationView will no longer be available.

https://developer.apple.com/documentation/swiftui/navigationview

I see! Thanks Chris…