Swiftui Navigation on iPad - How to Show Master List

SwiftUI Navigation on iPad - How to show master list

In portrait the default split view does not work. This may be fixed in future but it appears the current options are:

(a) change the navigation view style of your first list to .navigationViewStyle(StackNavigationViewStyle()) so the navigation will work like on iPhone and push each view.

(b) leave the style to default and only support landscape for iPad

(c) implement a UIKit split view controller

Swiftui [BUG] NavigationView and List not showing on iPad simulator only

According to answer of @Procrastin8, I am here to show the example code, you just need to add one line of code .navigationViewStyle(StackNavigationViewStyle()

import SwiftUI

struct LandmarkList: View {
var body: some View {
NavigationView {
List(landmarkData) { landmark in
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
.navigationBarTitle(Text("Landmarks"))
}.navigationViewStyle(StackNavigationViewStyle())
}
}

struct LandmarkList_Previews: PreviewProvider {
static var previews: some View {
ForEach(["iPhone SE", "iPhone XS Max"], id: \.self) { deviceName in
LandmarkList()
.previewDevice(PreviewDevice(rawValue: deviceName))
.previewDisplayName(deviceName)
}
}
}

Screenshot

Sample Image

Navigate inside master instead of detail in SplitView in SwiftUI

Just modify link that it is not a detail

demo

NavigationLink("Show the slave view HERE", destination: SlaveView())
.isDetailLink(false)

How to show same view as iPhone on iPad instead of Split view?

Hard to say without any code, but I bet you need to add .navigationViewStyle(StackNavigationViewStyle()) to your NavigationView to not get it in split view mode on the iPad:

NavigationView {
View1()
}.navigationViewStyle(StackNavigationViewStyle())


Related Topics



Leave a reply



Submit