0

When starting my app on iPadOS, there is a blank view/screen on the right side, so I need a solution to force the app to choose or to lunch with the firstDetailsView().

If there is no solution for this problem, how can I add a Text() View on the right side which tells the user something like that -> no DetailView is selected

The screen when launching the app

Here is the sourcecode ContentView.swift

import SwiftUI
struct ContentView: View {
    var body: some View {
        TabView {
            HomeView()
                .tabItem {
                    Image(systemName: "house.fill")
                    Text("Home")
                }
            SettingsView()
                .tabItem {
                    Image(systemName: "gear.circle")
                    Text("Settings")
                }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

SettingsView.swift

import SwiftUI

struct SettingsView: View {
    var body: some View {
        Text("Settings")
    }
}

struct SettingsView_Previews: PreviewProvider {
    static var previews: some View {
        SettingsView()
    }
}

HomeView.swift

import SwiftUI

struct HomeView: View {
    var body: some View {
        NavigationView {
            ScrollView {
                VStack (spacing: -15) {
                    NavigationLink(destination: firstDetailsView()) {
                        card(symbol: "1.square", color: Color.orange)
                    }
                    
                    NavigationLink(destination: secondDetailsView()) {
                        card(symbol: "2.square", color: Color.green)
                    }
                    
                    NavigationLink(destination: thirdDetailsView()) {
                        card(symbol: "3.square", color: Color.purple)
                    }
                }
                
                
            }
            .navigationTitle("Title")
            
        }
    }
}


struct card: View {
    var symbol: String
    var color: Color
    
    var body: some View {
        HStack {
            Text("Link to DetailView")
            Image(systemName: symbol)
        }
        .frame(maxWidth: .infinity, minHeight: 100)
        .bold()
        .foregroundColor(Color.white)
        .background(color)
        .padding()
    }
}

struct HomeView_Previews: PreviewProvider {
    static var previews: some View {
        HomeView()
    }
}

firstDetailsView.swift

import SwiftUI

struct firstDetailsView: View {
    var body: some View {
        
        ZStack {
            Color.orange
                .ignoresSafeArea()
            Text("firstDetailsView!")
        }
        
    }
}

struct firstDetailsView_Previews: PreviewProvider {
    static var previews: some View {
        firstDetailsView()
    }
}

secondDetailsView.swift

struct secondDetailsView: View {
    var body: some View {
        ZStack {
            Color.green
                .ignoresSafeArea()
            Text("secondDetailsView!")
        }
        
    }
}

struct secondDetailsView_Previews: PreviewProvider {
    static var previews: some View {
        secondDetailsView()
    }
}
  • IMHO it would be good if you could go through the documentation for `NavigationView` and understand. If you are starting new then use `NavigationStack` or `NavigationSplitView`. Do a small POC for navigation instead of jumping into building an app directly. – user1046037 Nov 08 '22 at 20:18
  • 1
    @user1046037 Thank you for your help! I read the documentation then I used the NavigationSplitView(sidebar: , detail: ) and it worked by adding a Text() View to the detail Closure – programmingGuy Nov 09 '22 at 21:42

0 Answers0