Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize the delete button in UITableView

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 ?

like image 265
Spire Avatar asked Dec 02 '12 13:12

Spire


2 Answers

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";
}
like image 58
Wubbe Avatar answered Sep 30 '22 14:09

Wubbe


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 .

like image 20
Manu Avatar answered Sep 30 '22 12:09

Manu