Given i have a view like this..
@State var tabIndex: Int = 0
var body: some View {
TabView(selection: $tabIndex)
{
Text("Tab 1").tabItem({
Image(systemName: "message")
}).tag(0)
Text("Tab 2").tabItem({
Image(systemName: "arkit")
}).tag(1)
Text("Tab 3").tabItem({
Image(systemName: "battery.100")
}).tag(2)
}.navigationBarTitle("Tabbed View")
}
This produces a view like this which is what is expected:
to add a navigation button to the bar i can use
.navigationBarItems(trailing:
Button(action: {print("Button was tapped")}) {
Image(systemName: "plus")
.resizable().frame(width: 20, height: 20)
})
Which adds the button as expected
Is there any way to only add (or show) the button based on a condition?
if (self.tabIndex == 1){
show button
}
else {
don't show button
}

TabViewembedded insideNavigationViewisn't a good choice. Instead every tab in theTabViewshould have its ownNavigationView. Like if there are three tabs, there should be threeNavigationViewif every tab needs their navigation hierarchy.