FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

Unable to present. Please file a bug.

Forums > SwiftUI

How I fix it ? My content is this:

               HStack {

                        VStack (alignment:.leading) {

                            NavigationLink(destination: Text("oi")) {
                                Text("Vinhedo")
                                    .font(.title)
                            }

                            NavigationLink(destination: Text("oi")) {
                                Text("Restaurante")
                                    .font(.title)
                            }

                            NavigationLink(destination: Text("oi")) {
                                Text("Cave")
                                    .font(.title)
                            }

                            NavigationLink(destination: Text("oi")) {
                                Text("Varejo")
                                    .font(.title)
                            }

                        }

                        Spacer()
                    }.padding(.horizontal,20)

                }.navigationTitle("Enoturismo")

            }.navigationViewStyle(StackNavigationViewStyle())
            Spacer()
        }

The error is: Unable to present. Please file a bug.

   

Have experienced a similar issue. See https://www.hackingwithswift.com/forums/swiftui/unable-to-present-please-file-a-bug/7846 Searching Google didn't gave any solutions. I experience this only on an iPad with a specific view I want to render; it is not happening on an iPhone. I am puzzled what this is.

1      

I have the same issue, a weird solution is given in this topic : https://developer.apple.com/forums/thread/677333

Add this with your others navigationLink :

NavigationLink(destination: EmptyView()) {
    EmptyView()
}

The hack works for me.

1      

Hacking with Swift is sponsored by Essential Developer

SPONSORED From August 2nd to 8th you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!

Save your spot now

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

Please show your entire content.

If I guess at what the left out parts look like and use this, it works fine for me:

struct PresentErrorView: View {
    var body: some View {
        NavigationView {
            HStack {

                VStack (alignment:.leading) {

                    NavigationLink(destination: Text("oi")) {
                        Text("Vinhedo")
                            .font(.title)
                    }

                    NavigationLink(destination: Text("oi")) {
                        Text("Restaurante")
                            .font(.title)
                    }

                    NavigationLink(destination: Text("oi")) {
                        Text("Cave")
                            .font(.title)
                    }

                    NavigationLink(destination: Text("oi")) {
                        Text("Varejo")
                            .font(.title)
                    }

                }

                Spacer()
            }
            .padding(.horizontal,20)
            .navigationTitle("Enoturismo")
        }
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

But, again, this is only a guess at what your entire content looks like.

   

You Take out scroll view? and put navigation view at top?

   

For me give me the same error, in all situations.

   

You Take out scroll view? and put navigation view at top?

There is no ScrollView in the sample code you posted. That's why I said to post your entire content. It's hard to reproduce an issue, let alone figure out a fix, if we aren't working with complete information.

   

The report is a bug, so it is worth filing with a sample of that code. Otherwise they may not ever fix it.

As to how to fix it, try removing what you can until it works. I wonder why you have a VStack embedded in a HStack though.

   

I wonder why you have a VStack embedded in a HStack though.

Nothing wrong with that, if it's what the design calls for.

   

What i need to do. All my firsts apps have this error!

   

Please post your entire content. It's hard to reproduce an issue, let alone figure out a fix, if we aren't working with complete information.

   

Below is how I fixed it in my scenario where I was seeing the error and not navigating to the correct view in iPhone when in landscape mode and iPad. iPhone in portrait also raised the error but still navigated correctly.

The NavigationViewOptions struct has the sample data and common code used for the fixed and broken version. Added and enum to highlight how it can be used to return different views based on option selected.

The NavigationViewBroken struct demonstrates the broken NavigationLink.

The NavigationViewWorking struct uses a single NavigationLink managed by two state variables one to store the selected option and the other to activate the navigation and a tap gesture on the Text label to update the state variables

import SwiftUI

struct NavigationViewOptions {
    enum OptionType { case main, optional }
    typealias Option = (id: UUID, value: String, type: Self.OptionType)
    static var options: [Option] = [
        (UUID(), "Option 1", .main),
        (UUID(), "Option 2", .optional),
        (UUID(), "Option 3", .main),
        (UUID(), "Option 4", .main),
        (UUID(), "Option 5", .optional),
    ]

    static func buildView(for option: Option) -> some View {
        switch option.type {
        case .main:
            return Text("Main Option selected\n\(option.value)").font(.title).fontWeight(.bold)
        case .optional:
            return Text("Optional Option selected\n\(option.value)").font(.title3).italic().fontWeight(.medium)
        }
    }
}
struct NavigationViewBroken: View {
    var body: some View {
        NavigationView {
            ScrollView{
                VStack (alignment:.leading) {
                    Text("BROKEN NAVIGATION:\nUnable to present. Please file a bug.")
                        .padding(.bottom, 40)

                    ForEach(NavigationViewOptions.options, id: \.id) { option in
                        NavigationLink(
                            destination: NavigationViewOptions.buildView(for: option),
                            label: {
                                Text(option.value)
                                    .font(.title)
                                    .padding(.vertical, 10)
                            })
                    }
                    Spacer()
                }
                .navigationTitle("Options")
            }
            // Initial Detail View
            Text("Select option from the left")
        }
    }
}
struct NavigationViewWorking: View {

    // State variables to leep track of what option has been tapped on and when to navigate to new view
    @State private var selectedOption: NavigationViewOptions.Option = (id:UUID(),"",.main)
    @State private var showDetail: Bool = false

    var body: some View {
        NavigationView {
            ScrollView{
                VStack (alignment:.leading) {
                    Text("NAVIGATION FIX FOR:\nUnable to present. Please file a bug.")
                        .padding(.bottom, 40)

                    ForEach(NavigationViewOptions.options, id: \.id) { option in
                        Text(option.value)
                            .font(.title)
                            .padding(.vertical, 10)
                            .foregroundColor(.accentColor) // same color as navigationLink
                            // handle tap on option
                            .onTapGesture {
                                selectedOption = option
                                showDetail = true
                            }
                    }
                    Spacer()
                    NavigationLink("", destination: NavigationViewOptions.buildView(for: selectedOption), isActive: $showDetail)
                        .opacity(0)
                }
                .navigationTitle("Options")
            }
            // INITIAL DETAIL VIEW
            Text("Select option from the left")
        }
    }
}

   

Hacking with Swift is sponsored by Essential Developer

SPONSORED From August 2nd to 8th you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!

Save your spot now

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

Reply to this topic…

You need to create an account or log in to reply.

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.