10

enter image description here

The problem is that the title and the item of the navigation bar does not disappear which is an unexpected behaviour.

struct DestinationView: View { @State private var showingActionSheet = false var body: some View { Text("DestinationView") .padding(.top, 100) .navigationBarTitle(Text("Destination"), displayMode: .inline) .navigationBarItems(trailing: Button(action: { print("tapped") }, label: { Text("second") })) .actionSheet(isPresented: self.$showingActionSheet) { () -> ActionSheet in ActionSheet(title: Text("Settings"), message: nil, buttons: [ .default(Text("Delete"), action: { }), .cancel() ]) } } } 
3
  • I have the same problem. It's really annoying. Do you fixed it? Commented Apr 15, 2020 at 12:52
  • 4
    I just figured out that issue only exists if you have BarButtonItems on the detail page Commented Apr 15, 2020 at 13:15
  • Any good Solution for this one so far? I ran into the exact same issue. But for me it just appears if i dismiss the View programmatically. Commented Oct 14, 2020 at 13:44

2 Answers 2

1

The problem is that the .navigationBarTitle(), .navigationBarItems() modifiers and the .actionSheet() modifier are under each other in code. (But it can be the .alert() or the .overlay() modifiers as well instead of .actionSheet())

The solution in this case:

struct DestinationView: View { @State private var showingActionSheet = false var body: some View { List { Text("DestinationView") .padding(.top, 100) .navigationBarTitle(Text("Destination"), displayMode: .inline) .navigationBarItems(trailing: Button(action: { print("tapped") }, label: { Text("second") })) } .actionSheet(isPresented: self.$showingActionSheet) { () -> ActionSheet in ActionSheet(title: Text("Settings"), message: nil, buttons: [ .default(Text("Delete"), action: { }), .cancel() ]) } } } 
Sign up to request clarification or add additional context in comments.

2 Comments

Is it a documented behavior that action sheet can't be used together with navigation bar customizations? I personally feel it's a bug in SwiftUI and filed a bug report. Just FYI: Another possible workaround could be to wrap the actionSheet in a conditional where the condition is the same as the one used for isPresented.
I also think it is a bug, I haven't found any documentation on that. The suggested workaround is a good idea.
0

Add

.navigationViewStyle(StackNavigationViewStyle()) 

to the NavigationView seems to fix it for me.

1 Comment

This does not work if you want to use it on iPad without the StackNavigationViewStyle.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.