2 years ago

#58566

test-img

user3386180

SwiftUI NavigationView Stuck after a Few Steps

I am walking my first steps with SwiftUI as I'm thinking about migrating my existing UIKit-based iOS app. It makes extensive use of split views. Ideally, there will be something like the iOS Mail app with a master/detail view as well as an additional (leftmost) column for selecting content, account, etc.

For now, I am stuck on some basic issues such as this one: I created a short list of navigation links and a default content to be shown when the app initially opens the detail view. This works as expected when navigating back and forth in "stacked" mode, i.e. on iPhone in portrait orientation. Changing to multiple-column view, e.g. iPhone max in landscape, the primary column is stuck after a few steps. In landscape view, I have to manually hide it by clicking on the detail, and in portrait view the detail view does no longer show at all.

import SwiftUI

@main
struct MyApp: App {
    
    var body: some Scene {
        WindowGroup {
            NavigationView {
                List {
                NavigationLink(destination: destination1) {
                    Text("Hello, World 1!")
                }
                NavigationLink(destination: destination2) {
                    Text("Hello, World 2!")
                }
                .navigationTitle("Primary")
                }
                Text("This is the default content shown when the navigation view is created.")
            }
        }
    }
        
    var destination1: some View {
        Text("Destination 1 text.")
            .navigationTitle("secondary 1")
    }
    var destination2: some View {
        Text("Destination 2 text.")
            .navigationTitle("secondary 2")
    }
}

swift

swiftui

swiftui-navigationlink

swiftui-navigationview

0 Answers

Your Answer

Accepted video resources