I'm trying to insert a actionSheet into action button into .tabItem. I only see a View with the text "Test 1". Can't make it display a menu with different options?. Thanks in advance.
@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 })
}
As Apple says:
Tab views only support tab items of type Text, Image, or an image followed by text. Passing any other type of view results in a visible but empty tab item.
You can use solution, which I described here. Shortly: you make empty tabItem (Text(" ")
), set Image
at needed position and use .onTapGesture
. There I also made example with ActionSheet