1

I have a SwiftUI master / detail NavigationView, with the master view being a list of countries, and the detail view being a list of cities in each country.

This works fine in every layout (macOS catalyst, iPhone, iPad) except on an iPad in portrait mode, where when the view is first selected I see nothing on screen apart from the drawer icon at top left.

How can I make the drawer be opened automatically when the tab containing this view appears? Alternatively retaining the same two column view as iPad landscape mode (with no drawer) would be acceptable - the detail column is narrow enough to permit this. I have however tried setting the NavigationView to two column mode, without success.

// master view
struct CountryListView : View {
    var body: some View {
        NavigationView {
            List(countries) { country in
                CountryView(country: country)
            }.navigationTitle("Countries")
        }
    }
}

// country list entry
struct CountryView {
    var body: some View {
        NavigationLink(destination: {
            CityListView(country: country).navigationTitle(country.name)
        }, label: {
            HStack {
                Text(country.name).lineLimit(1).truncationMode(.tail)
                Spacer()
                Text(country.iso).font(.footnote).layoutPriority(1)
            }
        }).disabled(country.cities.count == 0)
    }
}

// detail view (the list of Cities)
struct CityListView : View {
    @State var country : Country
    var body: some View {
        List(country.cities) { city in
            CityView(city: city)
        }
    }
}
Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • Until iOS 16 with `NavigationSplitView` this was a known thing many people just used the `stack` navigation style as an alternative but I think there was some "hack" for a while where people added padding to the `NavigationView` and it would force the drawer out. There is no built in way of doing this pre-ios16 – lorem ipsum Mar 16 '23 at 14:34
  • I've tried that, without success. my current work around is to enforce `.navigationViewStyle(.stack)` on every device :( – Alnitak Mar 16 '23 at 14:35
  • Yup, it was kind of crummy, you can try things like pushing a detail view or adding an another view that tells the user to rotate their screen below the List. There is no great solution. – lorem ipsum Mar 16 '23 at 14:40

0 Answers0