Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change iPhone UITableView delete button title while editing it

I need to change the title of the default delete button that appears when I attempt to delete a row from a UITableView after setting editing to YES.

like image 948
Mina Mikhael Avatar asked Oct 22 '09 13:10

Mina Mikhael


3 Answers

You can change it in UITableView delegate method

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
like image 171
Vladimir Avatar answered Oct 20 '22 17:10

Vladimir


Swift

Add this method to your UITableView delegate (probably your view controller).

func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
    return "Erase"
}

This makes the button say "Erase" but you can use any string you want.

enter image description here

My fuller answer is here.

like image 44
Suragch Avatar answered Oct 20 '22 17:10

Suragch


Swift 3

With a small difference _

func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
    return "Erase"
}
like image 40
missionMan Avatar answered Oct 20 '22 17:10

missionMan