How to change uitableview delete button text

IphoneIosUitableviewDelegates

Iphone Problem Overview


Hi there I am trying to change the text that is showing in the delete button when a user swipes a uitableviewcell inside my tableview.

I have seen an example in another question thread that says to use this tableview delegate

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

My question is, how do I use this method.. I am not sure how to use this.

Iphone Solutions


Solution 1 - Iphone

In your controller managing the UITableView you should implement the UITableviewDelegate and return the title you want for your method inside the titleForDeleteConfirmationButtonForRowAtIndexPath method.

Example:

@interface CategoryAddViewController : UITableViewController
@end

@implementation CategoryAddViewController
// ...
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"Please don't delete me!";
}

@end

Leaving you off with something like that:

enter image description here

Solution 2 - Iphone

In Swift it is equal, just method signature is diferent!

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

Solution 3 - Iphone

Just return the string that you want to display instead of delete. Say you wish to show "Erase" for all rows, the above function should contain:

return @"Erase";

Read THIS

Also in your .h file, add the UITableViewDelegate in case your view controller is not a UITableViewController already. That is it can be either:

@interface SomeView : UIViewController <UITableViewDelegate>

OR

@interface SomeView : UITableViewController

Solution 4 - Iphone

Swift 4.2

override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
        return "Erase"
    }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionC.JohnsView Question on Stackoverflow
Solution 1 - IphoneFaizan S.View Answer on Stackoverflow
Solution 2 - IphoneWelesView Answer on Stackoverflow
Solution 3 - IphoneBourneView Answer on Stackoverflow
Solution 4 - IphoneGopal KohliView Answer on Stackoverflow