Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Edit/Done button title in UINavigationBar in Swift [duplicate]

Tags:

ios

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.

like image 666
Mych Avatar asked May 16 '16 12:05

Mych


Video Answer


1 Answers

you want to work on setEditing method

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

and add the following line in viewDidLoad()

 self.navigationItem.leftBarButtonItem!.title = "Change"
like image 180
UdayM Avatar answered Oct 17 '22 09:10

UdayM