16

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.

Dimillian
  • 3,616
  • 4
  • 33
  • 53

7 Answers7

21

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()
    }
}
Dad
  • 6,388
  • 2
  • 28
  • 34
Aaron A
  • 225
  • 2
  • 7
  • 7
    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 – Aaron A Dec 17 '19 at 01:32
  • 4
    I thought I was going crazy! Thanks for posting this update. – djr Dec 17 '19 at 03:25
  • 3
    For me this problem only exists in the simulator. If I run it on a real device it's totally fine. – djr Dec 17 '19 at 05:31
  • @djr I just confirmed that it works fine on a real device. Thanks for sharing that. – Aaron A Dec 18 '19 at 01:21
  • 1
    Check out my solution [here](https://stackoverflow.com/a/59933501/4067700) – Victor Kushnerov Jan 27 '20 at 15:00
  • I am unable to get it to work on the actual device as well!? – Learn2Code Feb 19 '20 at 02:37
  • @Learn2code What device model do you have? and is it running iOS 13? – Aaron A Feb 23 '20 at 20:40
  • 1
    @AaronA I was able to get it to work... thank you for the follow-up. – Learn2Code Feb 24 '20 at 00:16
  • @Learn2Code I'm glad it helped. I'm looking forward to the new Xcode update that came out yesterday. Hopefully that update has solved the issue for us. – Aaron A Mar 26 '20 at 21:14
  • 1
    @AaronA; I'm on the fence in regards to the update. On one had sure they are great and fix bugs (hopefully don't introduce new one!?). On the other hand, its gonna then require the users to have the absolute latest patch for their iPhones, in order for them to d/l and use my app which is not always going to be the case. So I sticking with building in iOS 13 strictly (100% SwiftUI app) for that reason. So no matter what the patch fixes, it will do me no good at this time. Hope it does help you! – Learn2Code Mar 26 '20 at 22:30
  • @Learn2Code you bring up a very good point here. It's going to take some time before everyone catches up to the latest update. – Aaron A Mar 27 '20 at 02:27
  • I'm seeing this problem on the device as well, anyone else? – bkbeachlabs Jul 05 '23 at 21:04
17

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!")
    }
}
kontiki
  • 37,663
  • 13
  • 111
  • 125
  • This does not work. Im using Xcode 11 GM version. The text "Go" is disabled. – Just a coder Sep 18 '19 at 23:37
  • 2
    @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. – kontiki Sep 19 '19 at 04:38
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"))
}
Ekambaram E
  • 1,184
  • 1
  • 11
  • 9
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.

0

Try this:

 VStack{
     NavigationLink(destination: DetailView()) {
         Text("Push")
     }.navigationBarTitle(Text("Your Text")).isDetailLink(false)
 }
matt
  • 515,959
  • 87
  • 875
  • 1,141
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)
         }
    }
 }

}

wwarren07
  • 17
  • 9
-2

Try this:-

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

        }
    }
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56