如何解决这个问题? 解决方案 这看起来像是一个 SwiftUI 错误,值得向 Apple 提交反馈.临时解决方法是使用旧的 .navigationBarItems.使用 Xcode 12/iOS 14 进行测试.//... 其他代码.navigationBarTitle(详细信息").navigationBarItems(尾随:按钮(动作:{showActionSheet = 真}) {图像(系统名称:省略号.圆圈")})//.工具栏{//ToolbarItem(placement: .primaryAction) {////按钮(动作:{//showActionSheet = true//}) {//图像(系统名称:省略号.圆圈")//}//}//}I have the following example code:import SwiftUIstruct ContentView: View { var body: some View { NavigationView { NavigationLink(destination: DetailViewToolbarBug()) { Text("Unknown") } } }}struct DetailViewToolbarBug: View { @State private var showActionSheet = false var body: some View { VStack { NavigationLink(destination: DetailViewToolbarBug()) { Text("Unknown") } } .actionSheet(isPresented: $showActionSheet) { ActionSheet(title: Text("Optionen"), buttons: [ .default(Text("Add"), action: { }) ]) } .navigationBarTitle("Detail") .toolbar { ToolbarItem(placement: .primaryAction) { Button(action: { showActionSheet = true }) { Image(systemName: "ellipsis.circle") } } } }}The issue: If you navigate in two or more times and then open the action sheet, the back button (will have the name Detail in it) will disappear and not come back again.How to solve this? 解决方案 This looks like a SwiftUI bug and worth submitting feedback to Apple.Temporary workaround is to use old .navigationBarItems. Tested with Xcode 12 / iOS 14. // ... other code .navigationBarTitle("Detail") .navigationBarItems(trailing: Button(action: { showActionSheet = true }) { Image(systemName: "ellipsis.circle") } )// .toolbar {// ToolbarItem(placement: .primaryAction) {//// Button(action: {// showActionSheet = true// }) {// Image(systemName: "ellipsis.circle")// }// }// } 这篇关于ActionSheet 的工具栏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-16 03:50