When using NavigationSplitView
, it's common to have the detail view presenting information about something that was selected in the sidebar view. Usually that works great, but what happens when the app is first launched – what should be shown in the detail view then?
On iPhone this won't be a problem because users will only see the sidebar view, but on iPad it's more tricky – depending on the orientation, users might only see the detail view by default.
One easy solution here is to create a small view with some introductory instructions to help users get started. Here that means creating a new SwiftUI view called WelcomeView
, then give it this code:
struct WelcomeView: View {
var body: some View {
VStack {
Text("Welcome to SnowSeeker!")
.font(.largeTitle)
Text("Please select a resort from the left-hand menu; swipe from the left edge to show it.")
.foregroundStyle(.secondary)
}
}
}
That’s all just static text; it will only be shown when the app first launches, because as soon as the user taps any of our navigation links it will get replaced with whatever they were navigating to.
To put that into ContentView
so the two parts of our UI can be used side by side, replace the Text("Detail")
code we added earlier with this:
WelcomeView()
That’s enough for SwiftUI to understand exactly what we want. Try running the app on several different devices, both in portrait and landscape, to see how SwiftUI responds – if you’re using an iPad, you might see several different things depending on the device orientation and whether the app has all the screen to itself as opposed to using split screen.
SPONSORED Transform your career with the iOS Lead Essentials. This Black Friday, unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a free crash course.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.