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
.
How to change iPhone UITableView delete button title while editing it
Asked Answered
Are you aware we have no idea of what language/system/framework/platform you are talking about? –
Marindamarinduque
Hello guy! If you can just add ANYTHING about what are you even doing, it would quite nice... –
Decretal
ok, i've updated the question, sorry! –
Disenthral
You can change it in UITableView delegate method
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
Thank you, but i did add that method and returned NSString like that return @"Remove"; and nothing happened, it displays the default title "Delete" –
Disenthral
@Vladimir, is it possible to change background for Delete button? Defaults its showing Delete button with white background. –
Boycie
@Hemang, don't remember seeing white "delete" button in standard UI - I think there's no open API for that –
Yuille
@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
. –
Boycie @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. –
Boycie
@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 –
Yuille
what about if I want to change the background color of the delete button @Yuille –
Abnormality
@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. –
Yuille
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.
Swift 3
With a small difference _
func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
return "Erase"
}
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!
© 2022 - 2024 — McMap. All rights reserved.