20

I guess it might be a bug in beta 3 as the NavigationView is all broken. But a view like that:

struct GenreBadge : View {
    @EnvironmentObject var store: Store<AppState>
    let genre: Genre

    var body: some View {
        NavigationLink(destination: MoviesGenreList(genre: genre).environmentObject(store)) {
            RoundedBadge(text: genre.name)
        }
    }
}

is not triggering any push in the navigation stack. The view doens't seems interactive at all. If anyone found a workaround would be good, unless Apple is documenting this behaviour I would consider it broken until beta 4.

1
  • Check out my solution here Commented Jan 27, 2020 at 15:01

8 Answers 8

22

There seems to be a bug with the navigation link in Xcode version 11.3(11C29) which I have reported to Apple.

Note: This problem only appears in simulator. It works fine on a real device. Thanks to @djr

The below code works as expect the first time you use the navigation link. Unfortunately it becomes unresponsive the second time around.

import SwiftUI

struct ContentView : View {
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: SomeView()) {
                    Text("Hello!")
                }
            }
        }
    }
}

struct SomeView: View {
    var body: some View {
        Text("Detailed View")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Sign up to request clarification or add additional context in comments.

12 Comments

Update: It looks like Apple is on the case. Here is an update on the bug I reported: Recent Similar Reports: More than 10 Resolution: Potential fix identified - For a future OS update
I thought I was going crazy! Thanks for posting this update.
For me this problem only exists in the simulator. If I run it on a real device it's totally fine.
Check out my solution here
@AaronA I was able to get it to work... thank you for the follow-up.
|
19

Are you actually inside a NavigationView? The following works. But if I missed your point, maybe you can share a little more code.

import SwiftUI

struct ContentView : View {
    var body: some View {
        NavigationView {
            VStack {
                NavigationLink(destination: SomeView()) {
                    Text("Go!")
                }
            }
        }
    }
}

struct SomeView: View {
    var body: some View {
        Text("Detailed View Here!")
    }
}

2 Comments

This does not work. Im using Xcode 11 GM version. The text "Go" is disabled.
@iOSCalendarpatchthecode.com at some point, it stopped working. But it is easily solvable. The problem is buttons inside a NavigationView cannot be in the top of the hierarhcy. Just put it inside a VStack and it will work fine. I modified the code to show the change.
1

I had a custom onPress property for my view inside NavigationLink which was overriding the NavigationLink press. Removing the custom onPress handler fixed the issue.

var listView: some View {
        LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) {
            ForEach(data, id: \.self) { d in
                NavigationLink(value: d) {
                    SomeView(
                        onPress: { // Remove this onPress in SomeView, to remove onTap conflict
                            handleOnPress()
                        }
                    )
                    .frame(height: 264)
                }
            }
        }
        .navigationDestination(for: dataModel.self) { d in
            ViewToPush(data: d)
        }
    }

Comments

0

NavigationLink

A button that triggers a navigation presentation when pressed. This is a replacement for pushViewController

NavigationView {
    NavigationLink(destination:
        Text("Detail")
        .navigationBarTitle(Text("Detail"))
    ) {
        Text("Push")
    }.navigationBarTitle(Text("Master"))
}

Or make it more readable by use group destination into it own view DetailView

NavigationView {
    NavigationLink(destination: DetailView()) {
        Text("Push")
    }.navigationBarTitle(Text("Master"))
}

Comments

0

In Xcode 11.3.1, I experienced the same issue but I just had to quit xcode and restart my computer. This apparently fixed an issue (of course its 2021 right now) but I was able to follow apple's swiftui tutorial without any issues. I copied this code and tried it out... worked fine for me. Maybe the issue is your "play" button on the bottom right of your screen was toggled.

Comments

0

Try this:

 VStack{
     NavigationLink(destination: DetailView()) {
         Text("Push")
     }.navigationBarTitle(Text("Your Text")).isDetailLink(false)
 }

Comments

0

Put your NavigationLink inside a NavigationStack.

struct GenreBadge : View {
@EnvironmentObject var store: Store<AppState>
let genre: Genre

var body: some View {
    NavigationStack {
       NavigationLink(destination: MoviesGenreList(genre: genre).environmentObject(store)) {
         RoundedBadge(text: genre.name)
         }
    }
 }

}

Comments

-2

Try this:-

var body: some View {
        NavigationView {
        ZStack {
            NavigationLink(destination: YourView()) {
                Text("Go!")
            }
         }

        }
    }

1 Comment

Error "Cannot find 'NavigationButton' in scope"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.