简体   繁体   中英

SwiftUI: navigation bar shows title for first list item, otherwise shows “Back”

I have basic list and detail views set up as shown below. The problem is that the first detail view shows "< Inbox" as the back button while the other rows show "< Back". I've tried various options and places for .navigationBarTitle but haven't found any way to solve this.

Main / list view:

    var body: some View {
        NavigationView {
            List {
                ForEach(userData.message) { messageSection in
                    Section(header: Text(messageSection.id)) {
                             ForEach(messageSection.messages) { message in
                                NavigationLink(destination: MessageDetail(message: message)) {
                                    MessageRow(message: message)
                                }
                             }
                     }
                 }
                }.navigationBarTitle(Text("Inbox"), displayMode: .inline)
        }
    }

Detail view:

    var body: some View {
        ScrollView {
            VStack {
...
            }
        }.navigationBarTitle(Text("\(self.message.title) (\(self.message.preview))"), displayMode: .inline)
    }

When the title is too long to display in the space allocated for the left bar button, the system uses "Back" as the button title instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM