Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI NavigationLink for iOS 14.5 not working

I had the following code in Xcode 12.4 that worked perfectly

ScrollView(.horizontal, showsIndicators: false) {              LazyHGrid(rows: rows, spacing: 0) {                      HStack {                                      if (type == "Quiz") {                                          NavigationLink(destination: Quiz(id: quiz.id)) {                                                      VStack(alignment: .leading) {                                                              Text("Quiz")                             .font(.headline)                             .foregroundColor(.white)                             .padding(.top, 8)                             .padding(.leading)                           }                     .background(Color.green)                     .cornerRadius(12)                     .shadow(color: .green, radius: 3, x: 0.0, y: 0.0)                                              }                                          } else {                                              NavigationLink(destination: Survey(id: survey.id)) {                                                      VStack(alignment: .leading) {                                                              Text("Survey")                             .font(.headline)                             .foregroundColor(.white)                             .padding(.top, 8)                             .padding(.leading)                                                          }                     .background(Color.green)                     .cornerRadius(12)                     .shadow(color: .green, radius: 3, x: 0.0, y: 0.0)                                              }                                         } // End If                                 if (type == "Quiz") {                                         NavigationLink(destination: QuizResults(id: quiz.id)) {                                                     VStack(alignment: .leading) {                                                     Text("Quiz Results")                            .font(.headline)                            .foregroundColor(.white)                            .padding(.top, 8)                            .padding(.leading)                                              }                    .background(Color.blue)                    .cornerRadius(12)                    .shadow(color: .blue, radius: 3, x: 0.0, y: 0.0)                                                 }                                         } else {                                                 NavigationLink(destination: SurveyResults(id: survey.id)) {                                                         VStack(alignment: .leading) {                                                         Text("Survey Results")                            .font(.headline)                            .foregroundColor(.white)                            .padding(.top, 8)                            .padding(.leading)                                                 }                    .background(Color.blue)                    .cornerRadius(12)                    .shadow(color: .blue, radius: 3, x: 0.0, y: 0.0)                                                    }                                            }                             }       .padding([.leading, .trailing], 25)              } .frame(height: 100) 

I just updated Xcode to 12.5 and the above does not work any more.

It was working fine in 12.4!?

Now when I click the 'Quiz' element, it starts the transition to the Quiz View which is displays it but immediately closes the view and I'm back in the Detail View!?

Can someone see what I am doing wrong, and why now based on the update to 12.5 this stopped working?

UPDATE

I refined the code to the minimal possible reproducible form. What seems to be happening is that I have two or more NavigationLinks sets.

the first is the set to navigate the user to either the Quiz or Survey which the if statement addresses the user to the correct view to fill in.

Where the issue is in 12.5 is that the second set where the user can click to go see the overall results of the Quiz or Survey does not work when it's directly after the first navigation.

Like I said before hand it worked perfectly in 12.4 but seems like 12.5 does not agree with it. Can someone offer a better way for the user to click an element to either go fill in a quiz or survey or go see the results of a quiz or survey?

like image 242
Learn2Code Avatar asked Apr 27 '21 02:04

Learn2Code


People also ask

How does NavigationLink work SwiftUI?

NavigationLink in SwiftUI allows pushing a new destination view on a navigation controller. You can use NavigationLink in a list or decide to push a view programmatically. The latter enables you to trigger a new screen from a different location in your view.

What iOS does SwiftUI support?

SwiftUI runs on iOS 13, macOS 10.15, tvOS 13, and watchOS 6, or any future later versions of those platforms. This means if you work on an app that must support iOS N-1 or even N-2 – i.e., the current version and one or two before that – then you will be limited in terms of the features you can offer.

What version of Xcode do I need for SwiftUI?

To develop with SwiftUI we will need a minimum version of Xcode 11. Also, the devices where we want to run an application with SwiftUI will have to have versions equal to or higher than: iPhone/iPad iOS 13. MacBook macOS Catalina 10.15.


Video Answer


1 Answers

I got exactly the same problem, everything works fine with Xcode 12.4.

https://developer.apple.com/forums/thread/677333

I try to following this thread, it might work but on some case, I still have this bug.

       NavigationLink(destination: EmptyView()) {            EmptyView()        } 

Apparently, you can put this 3 lines of code close to your NavigationLink... If someone got a better answer I will really appreciate it !

like image 103
Steven Martreux Avatar answered Sep 21 '22 19:09

Steven Martreux