How can I change the title of a custom navigation bar button when the "delete" button of a table row that is under editing, is either tapped or dismissed?
The button is the "editBarButton". It is a custom navigation bar button. The initial title of it is "Edit". It must remain as "Edit" while the table is in non-editing mode, and it must change to "Done" when the table is in editing mode. Therefore, when a table row is swiped so as the "delete" appears, the title of the "editBarButton" must be "Done"; it must be "Edit" when the title leaves the editing mode, either if the "delete" is tapped or dismissed (i.e., dismissed by tapping the row under deletion anywhere else except from the "delete" button). Using the code below, the title changes to "Done" when a row is swiped and the "delete" is appearing. But I cannot find a way to make it have the "Edit" title again.
The "editBarButton" is connected with @IBAction func editBarButtonIsPressed(_ sender: Any), as shown below. Therefore, each time the button is tapped, the title of it changes (as well as the value of tableView.isEditing). The title of it is also set to "Done" when a swipe is applied on a row of the table. However, I cannot find a way to make its title change back to "Edit" when the "delete" button (that appears after the swipe) is tapped or dismissed.
@IBAction func editBarButtonIsPressed(_ sender: Any)
{
if tableView.isEditing { editBarButton.title = "Edit" }
else { editBarButton.title = "Done" }
tableView.setEditing(!tableView.isEditing, animated: true)
}
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle
{
editBarButton.title = "Done"
return .delete
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
if editingStyle == .delete
{
//here, the element of the array that is presented in the relevant row of the table, is deleted, as well as the row
}
}