7

I have the functionality for "Swipe to delete" the TableViewCell. I want to customize the Delete button. enter image description here

Is this possible, and how to access the Delete button ?

Spire
  • 1,055
  • 2
  • 17
  • 47
  • 1
    try these http://stackoverflow.com/q/8603431/194544 http://stackoverflow.com/q/1615469/194544 – beryllium Dec 02 '12 at 14:06
  • @beryllium so your advice would be to create a custom cell? But I have already build the cell, I'd rather set a gesture recognizer then make this one as a custom cell. – Spire Dec 02 '12 at 16:58
  • You want action for the delete button or you need to change the delete button – Manu Mar 22 '13 at 06:58
  • Just have a look at my answer but make sure you need to have a customcell @Spire – Manu Mar 22 '13 at 07:24
  • @Spire, How did you customize delete button. Share your answer. – Ganesh G May 09 '13 at 05:25

3 Answers3

13

If you only need to change the title of the button, you only need to add the titleForDeleteConfirmationButtonForRowAtIndexPath method.

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"NewButtonName";
}
Wubbe
  • 203
  • 3
  • 7
6

This method will be called when user performs the swipe action

Just Place this in your CustomCell

- (void)willTransitionToState:(UITableViewCellStateMask)state
    {
        [super willTransitionToState:state];
        if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask)
        {
            for (UIView *subview in self.subviews)
            {
                if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
                {
                    UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
                    [deleteBtn setImage:[UIImage imageNamed:@"arrow_left_s11.png"]];
                    [[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
                }
            }
        }
    }

You should not try that, you are not supposed to alter Apple's default views .

Manu
  • 4,730
  • 2
  • 20
  • 45
  • I have found another way to delete, but thanks for your effort. I will get mor educated on this as I will need it for another projects. thx **One thing, I dont use custom cell, that's why I needed info on how to change the DELETE appearance, to look like the Nudge button** – Spire Mar 22 '13 at 11:31
  • You should not try that, you are not supposed to alter Apple's default views . Did you see this ? – Manu Apr 18 '14 at 05:23
  • 2
    Not true, You can do all kinds of custom UI hacks and if they add to the product Apple will accept them. We do custom UI all the time. – Andres Canella May 28 '14 at 08:46
-2

Try this:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
  if (editingStyle == UITableViewCellEditingStyleDelete)
   {
    //   Your Code
    }
}
Anil
  • 2,430
  • 3
  • 37
  • 55
Kaushal Bisht
  • 476
  • 2
  • 11
  • Ok, and how to call the Delete button here in `// Your Code` section? How can I change it in `UIButtonTypeCustom`? – Spire Dec 04 '12 at 12:49
  • This is inBuilt functionality of Table , so you can do whatever you want , like removing value from array for e.g.- [idArray removeObjectAtIndex:indexPath.row]; where idArray is NSMutableArray having ids . In the end just reload your Table by calling [tableView reloaddata]; where tableView is your table's name. – Kaushal Bisht Dec 04 '12 at 12:52