21

Though application is universal but ipad screen is blank. I have added checked both iphone and ipad. When running app in iphone works fine, but in ipad is not showing anything.

struct UserListView: View {

    var userName:String
    @State var searchString:String = ""

    var body: some View {

        VStack {
            SearchBar(text: $searchString)
                    .padding()
                    .frame(height:44)
                    .foregroundColor(Color.white)
                    .background(Color.gray)

            List(userList) { user  in
                   NavigationLink(destination:UserDetailView(userObj:user)) {

                    UserListRow(userObj: user)
                       }.navigationBarTitle("User Detail")
                    }
           }
      }
}
Rock
  • 1,408
  • 1
  • 12
  • 27
  • 1
    I know how this will sound, but have you tried things on an iPad in *landscape*? There is a question from yesterday that I commented on (sorry, didn't have an answer) related to how Lists work on iPad - basically, it defaults to a SplitView and in portrait it shows... nothing (or else a detail screen). I've experienced this issue and my workaround was to find an alternative to using a List. Bug? Expected behavior? I don't know. Is there a property setting to fix this? I suggested to the OP to drill into available properties. –  Sep 12 '19 at 12:04
  • hi @dfd yes you are right i checked in landscape it is showing like spiltview in left side content showing in left side of iphone. but still question is , why ? and how ipad will work in swiftUI. – Rock Sep 12 '19 at 12:21
  • (1) I stand corrected. It's the `NavigationView` that's the issue, not a `List`. But... (2) I just wasted 20 minutes trying to find something/anything to change the behavior on a portrait iPad and came up empty-handed. (3) I checked the question from yesterday and nobody else even commented. https://stackoverflow.com/questions/57888032/swiftui-navigation-on-ipad-how-to-show-master-list#comment102204056_57888032 –  Sep 12 '19 at 14:06

3 Answers3

51

Add this modifier to the NavigationView it should work:

NavigationView {

}.navigationViewStyle(StackNavigationViewStyle())
Ekambaram E
  • 1,184
  • 1
  • 11
  • 9
  • Alternatively, now you can use NavigationStack instead of NavigationView. On iPhone I didn't see any difference between the two but on iPad, it now looks exactly the same as iPhone. No more blank start screens. – CaptainMJ Dec 12 '22 at 04:23
15

The screen is probably blank because nothing has been selected and there is nothing in the details view so you're seeing a blank details view. If you swipe in from the left side of the screen, the hidden master view will slide over and you can select an item to view the details in the main view.

I hope this is a SwiftUI bug (at at least a missing features) because I don't think anyone wants split views to work like this.

sirshannon
  • 196
  • 1
  • 4
0

I've found a simple work around for this!

If you just check the device type and then insert an empty view for the iPad case, the empty view will be inserted into the shelf and your target view will be displayed.

struct NotificationsControlView: View {


var body: some View {
    

    
    NavigationView{
        if UIDevice.current.userInterfaceIdiom == .pad {
            EmptyView()
            NotificationsView().navigationViewStyle(.stack)
                .navigationBarTitleDisplayMode(.inline)
                .hiddenNavigationBarStyle()

        } else {
            NotificationsView()
                .navigationViewStyle(.stack)
                .navigationBarTitleDisplayMode(.inline)
                .hiddenNavigationBarStyle()
        }
    }.navigationViewStyle(StackNavigationViewStyle())
}

}

Nick
  • 9
  • 1
  • 2