Group Group Group Group Group Group Group Group Group

Page 584, in the picture at left top corner, there is < Back button is only for departure not for arrival

Chapter 11 Lists & Navigation I just followed book to do til page 584.

Page 584, in the picture at left top corner, there is < Back button, can navigate back to content view. it is departure , which is behaviour the same thing in my simulator.

but my question is why in content view, I click arrivals to navigate to FlightBoard view. at left top corner ,it show < Mountain Airport. not show <Back

why arrivals is different to departure. you can see your page 592 the first image, also show < Mountain Airport. not show <Back

code in contenview

import SwiftUI

struct ContentView: View {
var flightInfo: [FlightInformation] = FlightInformation.generateFlights()

var body: some View {

NavigationView {
  ZStack {
    Image(systemName: "airplane")
      .resizable()
      .aspectRatio(contentMode: .fit)
      .opacity(0.1)
      .rotationEffect(.degrees(-90))
      .frame(width: 250, height: 250, alignment: .center)
    VStack(alignment: .leading, spacing: 5) {
      // 2
      NavigationLink(destination: FlightBoard(
               boardName: "Arrivals",
               flightData: self.flightInfo.arrivals())) {
                 // 3
                 Text("Arrivals")
             }
      NavigationLink(destination: FlightBoard(
              boardName: "Departures",flightData: self.flightInfo.departures())) {
                Text("Departures")
            }
      
   
  
      Spacer()
    }
    .font(.title)
    .padding(20)
    // 4
  }
  .navigationBarTitle(Text("Mountain Airport"))
}

}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

Code in FlightBoard

import SwiftUI

struct FlightBoard: View {
var boardName: String
var flightData: [FlightInformation]
var body: some View {

        List(flightData) { flight in
            Text("\(flight.airline) \(flight.number)")
            
            }.navigationBarTitle(boardName)
    
  
}

}

struct FlightBoard_Previews: PreviewProvider {
static var previews: some View {
FlightBoard(boardName: “Test”,flightData: FlightInformation.generateFlights())
}
}

is that swiftui has bug? same code, run later,
somehow , < Back button show up in Arrivals.

as in page 592 the first image in your book, there is no < back button either.

@yangwulong1978 I think what you’re seeing is less a bug and more SwiftUI/iOS making some decisions for you. The current default behavior for the back button is to show the title of the previous view. If iOS thinks the title of the back button is too long (based on device, other things in the navbar, etc.), it changes it to just be < Back to save space. I’ve not found it to be completely consistent when it’s near the boundary, hence why occasionally you’re seeing that change.

The lack of back on the screenshot is I think a mistake from when that was captured from the preview. I’ll make a note to update that in the new version.

Thank to reply. When I did above testing ,I just used one simulator iPhone 11 Pro Max. I did not use any other type of simulator. Just not quite understand same piece of code ,same simulator Why occasionally has different result. If device is different, has different result it is reasonable. If same device ,same code why behave different

I think that is a bug as I’ve observed the same behavior.