在UITableView中自定义删除按钮

Spi*_*ire 7 iphone xcode customization uibutton

我有"滑动删除"的功能TableViewCell.我想自定义删除按钮.在此输入图像描述

这可能,以及如何访问删除按钮?

Wub*_*bbe 12

如果您只需要更改按钮的标题,则只需添加titleForDeleteConfirmationButtonForRowAtIndexPath方法.

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"NewButtonName";
}
Run Code Online (Sandbox Code Playgroud)


Man*_*epa 6

用户执行滑动操作时将调用此方法

只需将其放入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];
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

你不应该尝试,你不应该改变Apple的默认视图.

  • 不是这样,你可以做各种自定义UI黑客,如果他们添加到产品,Apple将接受它们.我们一直在做自定义UI. (2认同)