-1

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
    }
}
ckc
  • 345
  • 4
  • 12
  • Please explain exactly what you're trying to do. Show what you've tried. Show an example so we know what you're talking about. – creeperspeak Dec 01 '17 at 00:10
  • What button are you referring to? Update your question with some relevant code. Clearly show where you need help. – rmaddy Dec 01 '17 at 00:16
  • Please do not post comments. [Edit] your question with all relevant details. – rmaddy Dec 01 '17 at 00:27
  • 1
    See https://stackoverflow.com/questions/40144020/how-to-change-uibarbuttonitem-text-during-runtime-cleanly-edit-done-e for the proper solution. – rmaddy Dec 01 '17 at 00:27
  • 1
    Your edited question still makes no sense. Please [edit] your question to clearly describe what button you are referring to and under what conditions it should do whatever it is that you want it to do. Post relevant code in your question as needed. – rmaddy Dec 01 '17 at 00:33

1 Answers1

0

I have found the answer. The following function must be used:

override func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?)
{
    editBarButton.title = "Edit"
}
ckc
  • 345
  • 4
  • 12