26

I am getting this message in the console every time I navigate to another screen:

[Assert] displayModeButtonItem is internally managed and not exposed for DoubleColumn style. Returning an empty, disconnected UIBarButtonItem to fulfill the non-null contract.

Currently I have navigation view set up in the entry point of the app like so

NavigationView {
        KeyboardView(matrixVM: matrixVM, isNavigationBarHidden: $isNavigationBarHidden)
            .background(Color("background")
            .edgesIgnoringSafeArea(.all))
            .navigationBarTitle("Workspace")
            .navigationBarHidden(self.isNavigationBarHidden)
            .onAppear {
                self.isNavigationBarHidden = true
        }
    }

And then inside the KeyboardView I have the navigationlink

NavigationLink(destination: NotebookView(isNavigationBarHidden: $isNavigationBarHidden, saved: matrixVM), label: {
                            Text("Notebooks")
                                .font(.system(size: 14, design: .rounded))
                                .fontWeight(.medium)
                                .foregroundColor(Color("text"))
                                .padding(.trailing, 10)
                        })

Inside the NotebookView I have a list of navigation links (each notebook linking to its detail page)

ScrollView(showsIndicators: false) {
                        ForEach(notebooks, id: \.self) { notebook in
                            
                            NavigationLink(destination: ExpandedSnippet(matrixVM: saved ,notebook: notebook)
                                            .navigationBarTitle("Notebook", displayMode: .inline)) {
                                SnippetCard(notebook: notebook, matrixVM: saved)
                                    .frame(width: UIScreen.main.bounds.width)
                            }
                            .padding(.bottom, 30)
                        }
                    }

Everything seems to be working but just a few hours ago it didn't (I was using tabbar and it suddenly started crashing after working for weeks). I feel like it's a bit of a mess and I am doing something wrong. Any idea why? Thanks for the help!

CodeBender
  • 35,668
  • 12
  • 125
  • 132
Barkin C.
  • 275
  • 3
  • 5

5 Answers5

26

I am getting this with Xcode 12.1 when running on the iPhone or iPhone simulator but not the iPad simulator.

Attaching this to the NavigationView fixed it for me.

.navigationViewStyle(StackNavigationViewStyle())
Scooter
  • 4,068
  • 4
  • 32
  • 47
  • 1
    If you still want to keep the double column style on iPad, you can [use a different style based on the size class](https://stackoverflow.com/a/67289627/14351818) – aheze May 30 '21 at 19:39
9

Using Xcode 12.1 (12A7403), this appears to be fixed.

The previous answer remains below for posterity.

I ran into this earlier as well using the latest Xcode 12 beta (12A8189).

This provides a simple MVP to demonstrate the problem.

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                NavigationLink(destination: DetailView()) {
                    Text("First View")
                }
            }
            .navigationViewStyle(StackNavigationViewStyle())
        }
    }
}

struct DetailView: View {
    var body: some View {
        List {
            NavigationLink(destination: Text("Detail Title")) {
                Text("New View")
            }
        }
        .navigationBarItems(trailing:
                                Button(action: {
                                    print("Clicked")
                                }) {
                                    Image(systemName: "square.and.arrow.up")
                                })
    }
}

The issue comes down to what device I use.

When running this on an iPhone, I will see the message that OP posts.

When running this on an iPad, I will not see any message.

Now, why is it doing this?

For starters, you can look at this Apple reference for the displayModeButtonItem that the assertion references.

Or, check out the screenshots of the above code in action.

iPhone:

enter image description here

iPad:

enter image description here

Notice how the iPad shows the icon for displayModeButtonItem, while the iPhone does not.

Based on this, my take is that Apple made a mistake. Maybe it will get fixed in the next release?

The best thing you can do would be to file a bug.

FWIW, I did look at the release notes and could not find any reference to this.

CodeBender
  • 35,668
  • 12
  • 125
  • 132
7

Attaching .navigationViewStyle(StackNavigationViewStyle()) to the NavigationView does indeed silence the error.

Unfortunately, this is not always a desirable solution, and can sometimes introduce another existing bug specific to StackNavigationViewStyle() in which: a selected list row's background color remains gray after navigating back.

Brandon C.
  • 410
  • 4
  • 8
7

After updating my iOS 13 app to iOS 14, I am seeing this error and my navbar was not working properly.

To fix this error, I just have to do one change:

NavigationView{
// other code
}
.navigationViewStyle(StackNavigationViewStyle())
Anthony Puitiza
  • 101
  • 1
  • 2
0

In my case, I received this error on a NavigationLink using the navigationBarItems() modifier. Adding navigationViewStyle(StackNavigationViewStyle()) to my NavigationView did not solve the issue. I also tried zIndex() and layoutPriority() to no avail. My issue was resolved by using the toolbar instead.

Before

.navigationBarItems(trailing:
    NavigationLink(
        destination: OtherView(),
        label: {
            trailingImage
        })
    )

After

.toolbar {
    ToolbarItem(placement: .navigationBarTrailing) {
        NavigationLink(
            destination: OtherView(),
            label: {
                trailingImage
            })
    }
}
Joery
  • 759
  • 4
  • 13
  • 33