I'm in the process of building a SwiftUI app with a Sidebar and Detail View. I've run into some issues and I need some help fixing them:
- When the app is launched, my detail view shows up at the right of the sidebar. Great! However, the button that is supposed to navigate to that view isn't highlighted, which could cause user confusion. How do I make this button "light up" (with that blue background indicating to the user that it is selected, highlighted) and make the code so that this view opens up when the app opens (like in other Apple apps, see Music and Files)
- When I click on one of my sidebar items (which are just NavigationLinks), the background doesn't turn blue (highlight) to indicate that item is selected. I feel like this would cause user confusion, and I'd like to figure out why my code doesn't do this. One side note and a useful piece of information: whenever I click the NavigationLink in the sidebar, the console prints this:
onChange(of: UpdateTrigger) action tried to update multiple times per frame.
- In the macOS app, upon launch, the detail view shows up. Great. What doesn't show up is my sidebar with the options on it. How do I make it so that the sidebar shows up no matter what unless the user specifies to remove it from view?
Attached are some images and my code. Thanks, y'all!
struct ContentView: View {
var body: some View {
// NavigationSplitView for the sidebar
NavigationSplitView {
// List of the options
List {
// NavigationLink for my button
NavigationLink {
// Linking to my main view that I want to show up upon launch of the app
MainView()
// Label to make it look pretty
} label: {
Label("Main View", systemImage: "icloud")
}
// Make the sidebar actually look like a sidebar
.listStyle(.sidebar)
}
// NavigationTitle at the top of the sidebar
.navigationTitle("Cling")
//
} detail: {
// Make it so that the main screen shows up upon launch (however, this doesn't make the button light up to signify that the user has selected that view)
MainView()
}
}
}