Monday, July 11, 2022
HomeiOS Developmentios - Swift: How one can change DetailView relying on SideBar Choice...

ios – Swift: How one can change DetailView relying on SideBar Choice State with SwiftUI 4?


Context

I’ve an issue with the brand new SwiftUI SideBar / NavigationLink idea.
I’ve created a easy 2 Column NavigationSplitView with a SideBar and a DetailView.

As soon as the App is launched, the preselected Timeline RootView seems because the DetailView. Nonetheless, once I choose a distinct SideBar Merchandise, the DetailView doesn’t change accordingly.


Code

struct SideBar: View {
    @State non-public var navigationItem: NavigationItem? = .timeline
    
    var physique: some View {
        NavigationSplitView {
            Listing(NavigationItem.allCases, id: .self, choice: $navigationItem) { navigationItem in
                NavigationLink(worth: navigationItem) {
                    Label(navigationItem.identify, systemImage: navigationItem.image)
                }
            }
        } element: {
            if let safeNavigationItem = navigationItem {
                safeNavigationItem.rootView
            } else {
                Textual content(String(localized: "choose.an.choice", defaultValue: "Choose an Choice"))
            }
        }
    }
}

Query

Do you’ve got any concept how I can clear up this difficulty? Thanks rather a lot to your help prematurely.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments