ActionSheet 的工具栏问题 [英] Toolbar issue with ActionSheet

查看:38
本文介绍了ActionSheet 的工具栏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下示例代码:

导入 SwiftUI结构内容视图:查看{var主体:一些视图{导航视图{NavigationLink(目的地:DetailViewToolbarBug()){文本(未知")}}}}struct DetailViewToolbarBug:查看{@State 私有 var showActionSheet = falsevar主体:一些视图{虚拟堆栈{NavigationLink(目的地:DetailViewToolbarBug()){文本(未知")}}.actionSheet(isPresented: $showActionSheet) {ActionSheet(title: Text(Optionen"),纽扣: [.default(文本(添加"),动作:{})])}.navigationBarTitle(详细信息").工具栏{工具栏项目(位置:.primaryAction){按钮(动作:{showActionSheet = 真}) {图像(系统名称:省略号.圆圈")}}}}}

问题:如果您导航两次或更多次,然后打开操作表,后退按钮(其中包含名称Detail)将消失并且不再回来.

如何解决这个问题?

解决方案

这看起来像是一个 SwiftUI 错误,值得向 Apple 提交反馈.

临时解决方法是使用旧的 .navigationBarItems.使用 Xcode 12/iOS 14 进行测试.

//... 其他代码.navigationBarTitle(详细信息").navigationBarItems(尾随:按钮(动作:{showActionSheet = 真}) {图像(系统名称:省略号.圆圈")})//.工具栏{//ToolbarItem(placement: .primaryAction) {////按钮(动作:{//showActionSheet = true//}) {//图像(系统名称:省略号.圆圈")//}//}//}

I have the following example code:

import SwiftUI

struct 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 的工具栏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆