Unwanted SplitView on modal view displayed on iPad

时光怂恿深爱的人放手 提交于 2021-02-11 05:57:27

问题


Testing my first SwiftUI app on iPad, I discovered that the modal views I display from my ContentView are displayed as Split views on the iPad, with the UI being truncated on the master side and the detail side is empty.

I did check both posts here :

Unwanted SplitView and, What's the equality of the UISplitView controller

But their solution of applying the .navigationViewStyle(StackNavigationViewStyle) to the NavigationView does not work for me :

I display my modals through user input (tap of a button) using the following method :
When a button is pressed, an Int value is passed to a local var (modalViewCaller) and then to the sheetContent() function.
Here is the end of my var body: some View and the following sheetContent func :


              } // END of main VStack
                .sheet(isPresented: $isModalPresented, content: sheetContent)
} // END of body

// modalViewCaller is the Int var I set upon button tap

    @ViewBuilder func sheetContent() -> some View {
        if modalViewCaller == 1 {
            firstModalView()
        } else if modalViewCaller == 2 {
            secondModalView()
        } else if modalViewCaller == 3 {
            thirdModalView()
        } 
    } // END of func sheetContent

Then in each of these modalViews, I apply the .navigationViewStyle(StackNavigationViewStyle) modifier to the NavigationView that encapsulate my entire view in var body: some View, but I get the following error : "Type 'StackNavigationViewStyle.Type' cannot conform to 'NavigationViewStyle'; only struct/enum/class types can conform to protocols"

Here is the end of my NavigationView in the modals :

} // End of VStack
                .navigationBarItems(
                    leading:
                    Button("Done") {
                        self.saveEdits()
                        self.presentationMode.wrappedValue.dismiss() // This dismisses the view
                    } // END of Button "Done"
                )
                .navigationBarTitle("Takeoff edition")

            } // END of Navigation View
            .navigationViewStyle(StackNavigationViewStyle)
            .onAppear { // assigned fetched event date, here it is available (was not in init())
            self.selectedDate = self.fetchedEvent.first?.eventDate ?? Date()
            }

        } // END of some View

I guess the solution posted was to apply that modifier from the ContentView NavigationView, but I don't have one (and don't want one because of all the screen real estate lost on top of my UI)


回答1:


Here is fix (it has to be constructed, ie. StackNavigationViewStyle()):

} // END of Navigation View
.navigationViewStyle(StackNavigationViewStyle()) // << here !! 


来源:https://stackoverflow.com/questions/61591551/unwanted-splitview-on-modal-view-displayed-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!