You can subclass CNContactViewController
to add a done
button to the navigationItem
.
Something like this:
import ContactsUI
class ContactDetailsViewController: CNContactViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateNavigationItem()
}
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
updateNavigationItem()
}
private func updateNavigationItem() {
if !isEditing {
// add a 0.5 seconds delay to add button after the editing animation finishes
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationItem.leftBarButtonItem = .init(
barButtonSystemItem: .done,
target: self,
action: #selector(self.doneTapped)
)
}
}
}
@objc private func doneTapped() {
dismiss(animated: true)
}
}
In order to make use of this class, make sure that ContactDetailsViewController
is embedded inside a UINavigationController
.
Although I'm so late to answer, but I hope this helps you or someone else.