Unable to present. Please file a bug.

Hello I got an console error, while my view are back from NavigationLink. I looked for some solutions but this doesn't help me. Any ideas what generate this error? Application doesn't crash, but im interested in what provide this error.



Code Block
import SwiftUI
struct AddictionListView: View {
    @StateObject private var addictionListVM: AddictionListViewModel = AddictionListViewModel()
    init() {
        UINavigationBar.appearance().barTintColor = UIColor(named: "BackgroundMain")        
    }
    var body: some View {
        NavigationView {
            ZStack {
                Color("BackgroundMain").ignoresSafeArea(.all)
                ScrollView {
                    LazyVStack {
                        ForEach(addictionListVM.addictions) { addiction in
                            NavigationLink(destination: Text(addiction.name)) {
                                AddictionCellView(addiction: addiction)
                            }.buttonStyle(PlainButtonStyle())
                        }
                    }.padding()
                }
                VStack {
                    Spacer()
                    HStack {
                        Spacer()
                        NavigationLink(
                            destination: AddNewAddictionView(),
                            label: {
                                Image(systemName: "plus").foregroundColor(.white).font(.title)
                            })
                            .frame(width: 50, height: 50, alignment: .center)
                            .background(Color.green.opacity(0.8))
                            .clipShape(Circle())
                            .padding(25)
                    }
                }
            }
            .navigationBarTitle("Habit tracker!", displayMode: .inline)
        }
        .onAppear(perform: addictionListVM.createExampleAddictions)
    }
}

Answered by hower in 676694022

I also experienced the same issue using multiple NavigationLinks where on iPhone most times worked OK even though the error was displayed in the console but on iPad links would not work in most cases. I've solved it using tap gesture and a single navigation link. You can see the fix on Paul Hudson's site.

https://www.hackingwithswift.com/forums/swiftui/unable-to-present-please-file-a-bug/7901/8237

Hi all - has anyone seen an actual fix for this issue? iPadOS 14.7 still exhibits this behavior in my apps. The multiple NavigationLinks in a single view appear to work on my iPhone app, but break on iPad and Mac Catalyst.

The EmptyView() workaround doesn't work for me. And I'm not interested in rewriting my entire navigation over this.

I've filed a bug, but haven't heard anything back from Apple. Has anyone heard back from the bugs they've filed?

This is super frustrating!

I tried to get a WWDC lab about this issue but the request was rejected.

I have the same problem for NavigationView with more than 2 NavigationLink. No problem with 1 ou 2 NavigationLink!

I had the same issue. Whenever the state of the ParentView is updated by some published property it messed up the navigation to the ChildView.

E.g.

LibraryView which can open BookViews and also download new books. During the download, the state is constantly updated (progress bar going 0-100). So whenever a book was downloading (continuous state updates of LibraryView), the NavigationLink messed up the navigation to BookView in one of two ways:

  1. popped the BookView from backstack immediately (like in https://developer.apple.com/forums/thread/677333) - this happened when I used just one NavigationLink and just changed its destination param depending on the current book.
  2. Yelled "Unable to present. Please file a bug." and caused the BookView to not properly register for its state changes on @Published viewmodel properties (so it was always stuck in "loading" state). - this happened when the NavigationLinks have been created inside ForEach.

The solution I used was to delegate the navigation to the viewmodel and stop listening to state changes there (cancel the Combine Publisher). Something like this:

    func navigateToBook(bookId: Int) {
        destinationBook = BookView(viewModel: createBookViewModel(bookId: Int(bookId)))
        cancellables.forEach { $0.cancel() }
        isBookPresented = true
    }

I honestly have no idea how to tie the lifecycle of viewModels to the lifecycle of SwiftUI views right now - NavigationLinks don't seem to be able to help, the onAppear / onDisappear are interleaved (i.e. the onAppear of ChildView will fire before onDisappear of ParentView).

It's a mess.

This problem finally stopped happening for me with the RC of Xcode and iOS 15.

Unable to present. Please file a bug.
 
 
Q