Starting with iOS 16, if you keep your navigation title inline, in the toolbar, you can allow a user to edit it in-place.
Navigation Titles
Here’s an example of a note taking app, showing the view to edit a note:
This view is a SwiftUI Form
embedded in a navigation stack with the note title presented as both an editable text field in the form and shown inline, in the navigation toolbar:
struct ItemEditView: View {
@ObservedObject var itemModel: ItemViewModel
@EnvironmentObject var store: ItemStore
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationStack {
ItemForm(title: $itemModel.title,
note: $itemModel.note,
date: itemModel.date) { update in
if update {
store.update(itemModel.id,
title: itemModel.title,
note: itemModel.note)
}
dismiss()
}
.navigationTitle(itemModel.title)
.navigationBarTitleDisplayMode(.inline)
}
}
}
Showing the title twice sometimes feels a bit redundant.
Renaming The Title
Starting with iOS 16, the navigationTitle view modifier can take a binding to a string. This allows the user to edit the title, in-place, in the toolbar.
In my example, I’ve removed the title text field from the form and changed the navigation title to be a binding to the title string:
NavigationStack {
ItemForm(note: $itemModel.note, date: itemModel.date) { ... }
.navigationTitle($itemModel.title)
.navigationBarTitleDisplayMode(.inline)
}
The title now appears in the toolbar with a small button next to it:
Tapping the button shows a drop-down menu with a rename action:
Tapping the rename action allows you to change the title:
Note that this only works when you show the title inline in the toolbar. It doesn’t work if you’re using the large title in an expanded navigation bar.