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: 10) {
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)
Button {
model.currentCourseTestSelected = nil
} label: {
Text("Complete")
}
}
}
}
}
My ContentView. I have a WelcomeView that consists of a button to go to 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.id.hash,
// 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
}
}