【问题标题】:SwiftUI actionSheet into .tabItemSwiftUI actionSheet 变成 .tabItem
【发布时间】:2020-03-20 11:25:46
【问题描述】:

我正在尝试将 actionSheet 插入到 .tabItem 中的操作按钮中。我只看到一个带有文本“测试 1”的视图。不能让它显示具有不同选项的菜单吗?提前致谢。

@State var showActionSheet = false

...

var actionSheet : ActionSheet{

    ActionSheet(title: Text("Crear"), message: Text("Selecciona opción"), buttons: [
        .default(Text("Opción 1")),
        .default(Text("Opción 2")),
        .destructive(Text("Cancel"))
    ])
}

...

        }.tag(1)

            Text("Test 1")

            .tabItem {
                VStack {
                    Image(systemName: "1.circle")


                    Button(action: {
                        self.showActionSheet.toggle()
                    }) {
                        Text("Display Action Sheet")
                    }
                    .actionSheet(isPresented: $showActionSheet, content: {
                        self.actionSheet  })

                }

【问题讨论】:

  • 这是不可能的。 TabItem 只需要一个 Image 和一个 Text,它的唯一功能就是切换视图。

标签: swiftui tabitem actionsheet


【解决方案1】:

作为苹果says

选项卡视图仅支持文本、图像或图像后跟文本类型的选项卡项。传递任何其他类型的视图会导致可见但为空的选项卡项。

您可以使用我描述的here 的解决方案。很快:您制作空 tabItem (Text(" ")),将Image 设置在需要的位置并使用.onTapGesture。在那里我还用ActionSheet做了例子

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多