Customize the delete button in UITableView

偶尔善良 提交于 2019-12-17 15:52:05

问题


I have the functionality for "Swipe to delete" the TableViewCell. I want to customize the Delete button.

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


回答1:


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 .




回答2:


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";
}



回答3:


Try this:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
  if (editingStyle == UITableViewCellEditingStyleDelete)
   {
    //   Your Code
    }
}


来源:https://stackoverflow.com/questions/13669920/customize-the-delete-button-in-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!