UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How Can I Bypass Initial View and Navigate Directly to Detail View?

Forums > SwiftUI

I've had no problem creating a List and allowing someone to click an item in the list to navigate to a detail view. But for over a week now I've been struggling with how to navigate directly to a detail view, e.g. from a Widget's widgetURL.

List(fetchRequest.wrappedValue, id: \.self){ item in
            ZStack{
                ItemCellView(item: item)
                        .padding(.vertical, 5)
                NavigationLink(destination: ItemDetailView(item: item)) {
                    EmptyView()
                }
                .frame(width: 0) // remove disclosure indicator
                .opacity(0) // remove disclosure indicator
            }
            .buttonStyle(PlainButtonStyle())
        }
        .listStyle(PlainListStyle())
        .padding(.horizontal, -20)
        .navigationBarTitle("Library (\(fetchRequest.wrappedValue.count))", displayMode: .large)
    }

This seems to work exactly as it should. But if I want to go directly to ItemDetailView, everything starts falling apart. I've seen some people say to wrap the whole thing in a NavigationView and add .onOpenURL to that. I've seen people saying to handle it in the initial view under @main, etc. There doesn't seem to be any consensus on what I would think is a common task.

3      

Just bumping this since it's been nearly three weeks and nobody's touched it ...

3      

Maybe because nobody here quite sure yet.

HWS+ Ultimate Portfolio App is going to deal with widgets and hope to get a better understanding of them.

3      

I think I have allready seen this on this project: https://github.com/Dimillian/ACHNBrowserUI

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.