0

I am running into an issue now. When I click on the button in my ResultsView, it does not go back to ContentView. It was previously working, and now is not for some reason. I have to use the navigation’s back button to go back to the ContentView. Another issue I am having is that the ResultsView will pop up and display quickly before the questions are being displayed. Does the version of Xcode matter in this case?

Here is my ResultsView

struct ResultsView: View {
    
    @EnvironmentObject var model: ContentViewModel
    
    var numberCorrect: Int
    
    
    var resultsText: String {
        if numberCorrect >= 8 {
            return "Awesome Job!"
        } else if numberCorrect >= 6 {
            return "Not bad. I think you can do better!"
        } else {
            return "You should study more"
        }
    }
    
    var body: some View {
        
        ZStack {
            Color.primaryColor
                .ignoresSafeArea()
            
            VStack (spacing: 30) {
               
                Text("\(numberCorrect) out of \(model.currentQuiz?.course.test.questions.count ?? 0)")
                    .font(.system(size: 50, weight: .heavy))
                    .foregroundColor(.white)
            
                Text(resultsText)
                    .font(.title)
                    .foregroundColor(.white)
                    .multilineTextAlignment(.center)
               
                Button {
                    model.currentCourseTestSelected = nil
                  
                } label: {
                    ZStack {
                        RoundedRectangle(cornerRadius: 20)
                            .fill(.white)
                            .frame(width: 200, height: 50)
                        Text("Complete")
                            .padding()
                    }
                }
               
                

            }
            
        }
        
      
    }
}

ContentView

struct ContentView: View {
    
    @EnvironmentObject var model: ContentViewModel
    
    var body: some View {
       
            ZStack {
                Color.primaryColor
                    .ignoresSafeArea()
                VStack(alignment: .leading) {
                    Text("Select a Quiz of Your Choice!")
                        .font(.title2)
                        .foregroundColor(.white)
                        .fontWeight(.bold)
                        .padding(.leading, 20)
                        .padding(.top, 40)
                    ScrollView {
                        LazyVStack{
                        ForEach(model.quizModules) {
                            quiz in
                            
                            NavigationLink(destination: QuizView()
                                .onAppear(perform: {
                                    model.getFirebaseQuestions(module: quiz) {
                                        model.beginQuizModule(quiz.course.test.id)
                                    }
                                  
                                }),
                                           tag: quiz.course.test.id.hash,
                                           selection: $model.currentCourseTestSelected)
                            {
                                CourseCard(category: quiz.category, description: quiz.course.description, image: quiz.course.image)
                            }
                           
                            
                        
                        }//ForEach Loop
                        }//LazyVStack
                        .navigationBarHidden(true)
                        .padding()
                    }
                }
            }//ScrollView
        //NavigationView
    }
}
Kevin
  • 27
  • 7
  • What button? Are you talking about the default back button, or something else? –  May 29 '22 at 21:45
  • I have a Button in the ResultsView that when press should return to ContentView but isn't. Based on suggestion from Brado below, it may have to deal with my NavigationView. I have a WelcomeView that contains a button moves into ContentView. That has the NavigationView which may be the issue. – Kevin Jun 01 '22 at 18:11

1 Answers1

0

As see from comments in ContentView, you had NavigationView(). Now there's no NavigationView there. Also you have .navigationBarHidden(true) and it hide back button in child view. I think your issue is here. Second question is needed to be explained more detail.

  • Oh okay. I have a WelcomeView that contains a button moves into ContentView. That has the NavigationView which may be the issue. – Kevin Jun 01 '22 at 18:10