SwiftUI: Change navigation bar title in the more tab?

Viewed 1810

I am begining to get my haead around swiftUI. So I have a simple tabView inside a Navigation View as below.

import SwiftUI

struct BasicView: View {
    var climbList: [ClimbDetail]
    var body: some View {
        NavigationView{
           VStack{
            Text("").navigationBarTitle("Climbers Log", displayMode:.inline)
                TabView {
                    Text("Search").tabItem{
                        Image(systemName:"magnifyingglass")
                        Text("Search")
                    }
                    Text("Stats").tabItem{
                        Image(systemName:"list.dash")
                        Text("Stats")
                    }
                    ClimbList(climbs: climbList).tabItem{
                        Image(systemName: "square")
                        Text("Climbs")
                    }
                    Text("Log").tabItem{
                        Image(systemName:"square.and.pencil")
                        Text("Log")
                    }
                    
                    Text("Profile").tabItem{
                        Image(systemName:"person.circle")
                        Text("Profile")
                    }
                    Text("Settings").tabItem{
                        Image(systemName:"gear")
                        Text("Settings")
                    }
                    Text("Add Climb").tabItem{
                        Image(systemName:"plus")
                        Text("Add Climb")
                    }
                }
            }
        }
    }
}

Genrally it works as expected, however as I have 7 tabs it defults to the 'More' tab for the 5th tab. This is fine and good for the user.

However my issue is when you click the 'More' tab you get the a title bar and edit button with 'More' as the title. Which appears below the title bar I have set above.

Title errors

So my question is how can I hide my titleBar when the user is on the 'More' tab and only show it inside the other tabs?

1 Answers

First off all, thanks for the question. I didn't know Apple provides More page by default for too long TabBars. I always needed that.

Back to you question, you just need to rearrange things. First off all, make the TabBar top level. Then a NavigationView and here comes your content. Later on you might outsource every view, to an own file.

TabView {

    NavigationView
    {
        VStack
        {
            Text("Search")
        }
        .navigationBarTitle("Climbers Log", displayMode:.inline)
    }.tabItem {
        Image(systemName:"magnifyingglass")
        Text("Search")
    }

 

Every view takes it own NavigationView.. and then it works.

Related