Mych Mych - 6 months ago 64
Swift Question

How to change Edit/Done button title in UINavigationBar in Swift

I'm displaying an editButtonItem in my tableview but I need to change the text of Edit and Done to Change and Cancel. All the examples I've found so far are in Objective-C... I need Swift syntax.

I have the following in viewDidLoad function...

self.navigationItem.leftBarButtonItem = self.editButtonItem()


... which displays the standard Edit/Done button item.

Answer

you want to work on setEditing method

override func setEditing (editing:Bool, animated:Bool)
{
   super.setEditing(editing,animated:animated)
   if(self.editing)
   {
        self.editButtonItem().title = "Cancel"
   }else
   {
        self.editButtonItem().title = "Change"
   }
 }