Это скрывает кнопку "Назад" и заменяет ее на кнопку добавления в Swift:
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
// This hides the back button while in editing mode, which makes room for an add item button
self.navigationItem.setHidesBackButton(editing, animated: animated)
if editing {
// This adds the add item button
let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTapped))
// Use the animated setter for the left button so that add button fades in while the back button fades out
self.navigationItem.setLeftBarButton(addButton, animated: animated)
self.enableBackGesture(enabled: false)
} else {
// This removes the add item button
self.navigationItem.setLeftBarButton(nil, animated: animated)
self.enableBackGesture(enabled: true)
}
}
func enableBackGesture(enabled: Bool) {
// In addition to removing the back button and adding the add item button while in edit mode, the user can still exit to the previous screen with a left-to-right swipe gesture in iOS 7 and later. This code disables this action while in edit mode.
if let navigationController = self.navigationController {
if let interactivePopGestureRecognizer = navigationController.interactivePopGestureRecognizer {
interactivePopGestureRecognizer.isEnabled = enabled
}
}
}