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
.
Asked
Active
Viewed 1.7k times
33

Suragch
- 484,302
- 314
- 1,365
- 1,393

Mina Mikhael
- 2,825
- 6
- 27
- 31
-
2Are you aware we have no idea of what language/system/framework/platform you are talking about? – PhiLho Oct 22 '09 at 13:24
-
Hello guy! If you can just add ANYTHING about what are you even doing, it would quite nice... – Trick Oct 22 '09 at 13:26
-
ok, i've updated the question, sorry! – Mina Mikhael Oct 22 '09 at 13:33
4 Answers
89
You can change it in UITableView delegate method
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

Vladimir
- 170,431
- 36
- 387
- 313
-
Thank you, but i did add that method and returned NSString like that return @"Remove"; and nothing happened, it displays the default title "Delete" – Mina Mikhael Oct 22 '09 at 13:59
-
1@Vladimir, is it possible to change background for Delete button? Defaults its showing Delete button with white background. – Hemang Jun 14 '12 at 07:39
-
@Hemang, don't remember seeing white "delete" button in standard UI - I think there's no open API for that – Vladimir Jun 14 '12 at 07:43
-
@Vladimir, Sorry! Its misunderstanding there! The Delete button with red color only, but it views background is of white color. Button is at center of that view. Its not my custom view or anything, I just override this method `- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath` and it will showing me Delete button when I swipe on any cell in my `UITableView`. – Hemang Jun 14 '12 at 14:09
-
@Vladimir, What I want to do is to clear the background of that view! So that only Delete button will be show on any cell. – Hemang Jun 14 '12 at 14:10
-
@Hemang, not sure, may be setting cell's background color to clearColor may help? delete button just comes over cell's contentView or the cell itself and does not add any extra background, need to experiment with that to be sure – Vladimir Jun 14 '12 at 14:13
-
what about if I want to change the background color of the delete button @Vladimir – Gajendra Rawat Jul 15 '14 at 05:21
-
@007, afaik there's no public api for that. You can try to check views hierarchy and change background directly. But keep in mind that as it is implementation details this structure may change (and has already changed) between ios versions. – Vladimir Jul 15 '14 at 07:43
7
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.
My fuller answer is here.

Suragch
- 484,302
- 314
- 1,365
- 1,393
4
Swift 3
With a small difference _
func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
return "Erase"
}

missionMan
- 873
- 8
- 21
0
For those who already have implemented method 'titleForDeleteConfirmationButtonForRowAtIndexPath' and still see same 'Delete' text.
Try to type in method from scratch with autocompletion, because I copied someone's and it has a little bit different older notation and didn't get called!

Vitya Shurapov
- 2,200
- 2
- 27
- 32