SwiftUI: Extra line in NavigationStack

Hi, I know its a simple thing, but I cannot figure it out.

I have a list of items going to another view using NavigationStack. Everything seems fine, but when I go into the list, I have two back buttons, the title is shifted down, and its just annoying.

Thanks for the help.

Here's my code:




struct ImportantNumbers: View {

  

  var body: some View {

    

    NavigationStack {

      List(INDDataService.getAll(), id: \.id) { data in

        

        NavigationLink(value: data)

        {

           

          HStack {

            

            Image(systemName: "circle.fill")

              .foregroundColor(.green)

            

            Text(data.name)

              .fontWeight(.bold)

            

            

              .navigationTitle("Important U.S. ADA Numbers")

              .navigationBarTitleDisplayMode(.inline)

          }

            

              .navigationDestination(for: INDData.self) {  data in

                

                Spacer()

                

                Image(data.logo)

                  .resizable()

                  .frame(width: 200, height: 200)

                

                Spacer()

                

                Text(data.phone)

                  .font(.system(size: 30, weight: .bold, design: .rounded))

                

                Spacer()

                

                  .navigationTitle(data.name)

                

              }

            

              

            

          }

          

          

        }

      }

      

    }

    

  }



struct ImportantNumbers_Previews: PreviewProvider {

    static var previews: some View {

        ImportantNumbers()

    }

}

Replies

Could you show the View that leads to the one you presented ? I cannot see the Image(systemName: "circle.fill") for instance.

You have defined 2 navigationTitle. Why ? What are they ?

What is the content of data.name in this case ? ADA 1990 ?

Please, when posting code, use Paste and Match Style, to avoid all the extra blank lines. And reduce the size of image.

struct ImportantNumbers: View {
    
    var body: some View {
        NavigationStack {
            
            List(INDDataService.getAll(), id: \.id) { data in
                NavigationLink(value: data)
                {
                    HStack {
                        Image(systemName: "circle.fill")
                            .foregroundColor(.green)
                        Text(data.name)
                            .fontWeight(.bold)
                            .navigationTitle("Important U.S. ADA Numbers")
                            .navigationBarTitleDisplayMode(.inline)
                        
                    }
                    
                    .navigationDestination(for: INDData.self) {  data in
                        Spacer()
                        
                        Image(data.logo)
                            .resizable()
                            .frame(width: 200, height: 200)
                        
                        Spacer()
                        
                        Text(data.phone)
                            .font(.system(size: 30, weight: .bold, design: .rounded))
                        
                        Spacer()
                            .navigationTitle(data.name)
                    }
                }
            }
            
        }
    }
}



struct ImportantNumbers_Previews: PreviewProvider {

    static var previews: some View {

        ImportantNumbers()

    }

}

The 2 NavigationTitles are for the listView and then the DetaiView.

The data.name is coming from an array thats in another Swift file. Its where the information is coming from.

I did not know about pasting code with the Paste and Match style. I'll remember that for the next time.

Here's a screen shot of the previous screen before the original one.

Thanks.