0

我正在尝试将 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  })

                }
4

1 回答 1

0

正如苹果所说

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

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

于 2019-11-25T08:06:14.193 回答