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)
}
}
}