Reputation: 1697
My app is working as expected across all iPhone models, but when running on iPad I notice that the my application content, which is wrapped within a NavigationView
, only displays in the iPad's sidebar, and only after tapping the 'Back` toolbar button.
var body: some View {
NavigationView{
ZStack{
...
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
VStack {
Text("Add Light to Your Journey")
.font(Font.custom("EduTASBeginner-Regular", size: 24))
...
}
}
I found a similar question on SO that suggested adding the attribute .navigationViewStyle(.stack)
, but this did not change the way the app is displayed on iPad:
Note the solution on this similar post also did not resolve the issue.
Upvotes: 9
Views: 2589
Reputation: 91
You can just use NavigationStack
instead of NavigationView
, and it will resolve the issue.
var body: some View {
NavigationStack{
ZStack{
...
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
VStack {
Text("Add Light to Your Journey")
.font(Font.custom("EduTASBeginner-Regular", size: 24))
...
}
}
Upvotes: 3
Reputation: 1697
As noted in the comments on the linked post, the .navigationViewStyle(StackNavigationViewStyle())
must be applied directly to the NavigationView
, and not a view contained therein as with .navigationTitle
Upvotes: 18