NavigationStack - NavigationPath Issue: View will not push when triggered from Detail View ( iOS17 )

78 views Asked by At

I am trying to convert my project to the new NavigationStack in Xcode 15 and am having an issue push a new view from a detailed view.

I have a Student List View (stdntListView) that passes the Student's details and NavigationPath to a Student Details View (stdntDetsView) when the user taps on a Student in the list using this code:

Student List View (stdntListView):

/// navigationDestination = manages the push of the Student
/// details view ( stdntDetsView ) when the user taps on a Student
.navigationDestination(for: Students.self) { student in
stdntDetsView(student: student, navPath: navPath)
}

When the user taps on a Review Pending Charges field on the Student Details View (stdntDetsView), it should push a Charges List View (chrgListView) however, it's not working.

I'm using the code structure for all my other view however, this one is the only one that does not seem to work. Here is the code for my Student Detail View (stdntDetsView).

import SwiftUI

// MARK: stdntDetsView
// This is the Student Details View of the CoachCents app

// MARK: Define Student Object
class ModStdnt: ObservableObject {
@Published var stdntID: UUID = UUID()
@Published var stdntName: String = ""
@Published var stdntClub: String = ""
@Published var stdntEmail: String = ""
@Published var stdntMobile: String = ""
@Published var stdntStatus: Bool = false
@Published var stdntBalance: NSDecimalNumber = 0.00
}

// MARK: Define Navigation Path Object
class NavPath: ObservableObject {
@Published var passedPath: NavigationPath = NavigationPath()
}

struct stdntDetsView: View {

// Injects an instance of the Core Data database for this app
@Environment(\.managedObjectContext) var managedObjectContext

// Injects the User Defaults for the CoachCents app
@EnvironmentObject var defaults: UserDefaults

// The variables below manages the Student details
@ObservedObject var modStdnt = ModStdnt()

// The variables below manages the Navigation Path details
@ObservedObject var navPath = NavPath()

// The variable student manages the values for passed Student
let student: Students

// Load variable student with values from CoreDate record
init (student: Students, navPath: NavigationPath) {
    
    self.student = student
    self.modStdnt.stdntID = student.stdntID!
    self.modStdnt.stdntName = student.stdntName!
    self.modStdnt.stdntClub = student.stdntClub!
    self.modStdnt.stdntEmail = student.stdntEmail!
    self.modStdnt.stdntMobile = student.stdntMobile!
    self.modStdnt.stdntStatus = student.stdntStatus
    self.modStdnt.stdntBalance = student.stdntBalance ?? 0.00
    
    self.navPath.passedPath = navPath.self
    
}

// The variable filterTypeChrg manages how Charges are filtered
// filterTypeChrg: Options are "Date" or "Student"
@State var filterTypeChrg = "Select Date"

// The variable filterDate manages the date filter for Charges
@State var filterDate: Date = Date()

// The variable filterStudent manages the student filter for Charges
@State var filterStudent = ""

// The variable filterStdntLock locks current Student in any filter
@State var filterStdntLock: Bool = false

// The variable filterStatusChrg manages the status filter for Charges
@State var filterStatusChrg: String = "Pending"

/// enum is a user-defined data type that has a fixed set of related values
/// navOptions is a set of options that relate to corresponding views
enum navOptions {
    
    ///  .... push Charges List view ( chrgListView )
    case charges
    
}

// The variable chrgInvNmbr manages the selected Charge Invoice Number
@State var chrgInvNmbr: String = "Pending"

// These variables are used to pass values between views
@State var selectInstruction: String = ""

var body: some View {
    
    VStack() {
        
        // MARK: Review Pending Charges
        // Review Pending Charges button
        Group {
            
            sbvCurLngNB(passLabel: "Pending Charges", passNSD: invCurChrgs(passedDefaults:             defaults, passedStdntID: modStdnt.stdntID, passedInvNmbr: "Pending", passedType: "Student", passedStatus: "Pending").totChrgSub, passDefault: "$0.00", passValue: "", passSelect: true )
            
            // FixIt: Ensures User can tap on Whitespace
                .contentShape(Rectangle())
            
            // Manages the tap on the 'Review Pending Charges' button
                .onTapGesture {
                    
                    filterTypeChrg = "Select Student"
                    
                    filterDate = Date()
                    
                    filterStudent = modStdnt.stdntName
                    
                    filterStdntLock = true
                    
                    filterStatusChrg = "Pending"
                    
                    // Clear Charge Modified Flag (chrgModFlg) for all Charges
                    _ = chrgModFlg(passedAction: "clearAll")
                    
                    /// If user selects Charges button, hide Navigation View ( navView )
                    /// If user selects Charges button, pop Charges Nav View ( chrgsListView )
                    navPath.passedPath.append(navOptions.charges)
                    
                }
        }
        
        /// navigationDestination = associates a view with a data ...
        /// ... type (navOptions) for use within a navigation stack
        .navigationDestination(for: navOptions.self) { selection in
            
            /// Set-up switch to process each Navigation Opiton ( navOption )
            switch selection {
                
                /// If the Navigation Option ( navOption ) is .add ...
            case .charges :
                
                /// .... push Charges List view ( chrgListView )
                chrgListView(navPath: $navPath.passedPath, filterTypeChrg: $filterTypeChrg, filterDate: $filterDate, filterStudent: $filterStudent, filterStdntLock: $filterStdntLock, filterStatusChrg: $filterStatusChrg, filterInvoice: $chrgInvNmbr, selectStdntName: $filterStudent, selectInstruction: $selectInstruction)
                
            }
        }
    }
}
}

Oddly, I tried adding a break point on the "case .charges" line and it does not break, thinking that the .navigationDestination is not being triggered.

Not sure where to go from here.

Oddly, I tried adding a break point on the "case .charges" line and it does not break, thinking that the .navigationDestination is not being triggered.

Not sure where to go from here.

0

There are 0 answers