3

I need my TabBar to disappear if I click on a NavigationLink. I know you can achieve that in iOS 14 with the following code:

 NavigationView{
        TabView{
            View1().tabItem {
                Image(systemName: "house.fill")
                Text("Home")
            }
        }
    }

And View1:

struct View1: some View {
var body: some View {
    NavigationView{
        NavigationLink(destination: Text("New Page without the Tabbar")) {
            Text("Link")
        }
    }
}
}

But somehow this don't works in iOS 15... Are there any other workarounds?

M.Abdullah Iqbal
  • 219
  • 1
  • 17
Boothosh81
  • 387
  • 1
  • 5
  • 24
  • Could you just use a `fullScreenCover` or `sheet` to present the destination instead of a `NavigationLink`? Why fight the system? – Steve M Nov 07 '21 at 19:59

1 Answers1

-2

You could try using only one NavigationView, like in this example:

import SwiftUI

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    var body: some View {
        NavigationView {
            TabView {
                View1().tabItem {
                    Image(systemName: "house.fill")
                    Text("Home")
                }
            }
        }
    }
}

struct View1: View {
    var body: some View {
        // ---> here no NavigationView
        NavigationLink(destination: Text("New Page without the Tabbar")) {
            Text("Link")
        }
    }
}
  • The answer works well for me with the code provided, the TabBar disappears when I click on the NavigationLink, and this is what the question is about for ios 15. Tested on ios 15 and macCatalyst 12 on real devices, using macos 12.1 beta, Xcode 13.1. Does this not work for someone? or why the down vote? – workingdog support Ukraine Nov 02 '21 at 12:09
  • 1
    There is a problem: You can only set one Navigationtitle per NavigationView. That means if the TabBar contains 3 Tabs, they have all the same Heading / Toolbar. –  Nov 03 '21 at 08:51
  • 2
    As @Max said, this isn't working if the TabBar has multiple different Tabs with Different Headings :( – Boothosh81 Nov 03 '21 at 13:24
  • humm, a bit confused here, @Max is talking about `...one Navigationtitle per NavigationView..`, and you talk about `TabBar has multiple different Tabs with Different Headings`. Could you show us an example code that replicate your issue with the features you require. – workingdog support Ukraine Nov 09 '21 at 06:12