UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on 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.

3      

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.

4      

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.

4      

Hacking with Swift is sponsored by Essential Developer

SPONSORED 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! Hurry up because it'll be available only until April 28th.

Click to save your free 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.

3      

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

3      

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

3      

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.

3      

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.

3      

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

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

3      

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

3      

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.

3      

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")
        }
    }
}

3      

I'm (now) encountering this in an application I'm writing for macOS. The truly interesting part, to me, is that when I was working on it in April of 2021 I did not have the problem. I stopped work for a while and now, in August, the same code now evidences the problem.

The problem seems to lie in how the NavigationView swaps out the destination view.

My situation: my app has three distinct classes of editable objects: people, households, and events. My UI tries to do as Xcode does, with a list of objects (grouped by type) on the left, and the appropriate editor view on the right. In the event that nothing is selected, the view just shows a prompt text, "Select something to edit."

So, at launch, there's the list on the left with the objects grouped inside DisclosureGroups by class, and on the right is the select something view. Click on a person's NavigationLink and the person editor is displayed with that person's information. Click on any other person or any event or household and the 'Unable to present' message displays in the console. Click on a disclosure triangle and the select something view gets displayed again. Now click on any NavigationLink and the appropriate editor appears.

This suggests that there's some state within the NavigationView that isn't getting updated properly.

3      

@State private var showDetail: Bool = false

can be skipeped in the last example, by using the following:

@State private var selectedOption: NavigationViewOptions.Option? = nil
...
NavigationLink("", destination: NavigationViewOptions.buildView(for: selectedOption),
  isActive: Binding<Bool>(get: {
    selectedOption != nil
  }, set: { value in
    if !value {
      selectedOption = nil
    }
  })
  .opacity(0)

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED 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! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.