UITableViewCell自定义删除按钮

时间:2009-11-23 00:23:40

标签: iphone uitableview

我想在uitableview单元格进入编辑模式时放置我自己的自定义删除按钮,类似于插入的“+”添加按钮,只是与“+”按钮位于相同位置的红色“x”是。我该怎么做?

3 个答案:

答案 0 :(得分:1)

尝试使用单元格willTransitionToState实现它。

在CustomTableCell.m中这样:

- (void)willTransitionToState:(UITableViewCellStateMask)state{
    if (state == UITableViewCellStateShowingEditControlMask) {
        customEditBtn = [[UIButton alloc] initWithFrame:CGRectMake( -32, 0, 42, self.contentView.height)];
        customEditBtn.adjustsImageWhenHighlighted = NO;
        [customEditBtn setImage:_image forState:UIControlStateNormal];
        [self.contentView addSubview:customEditBtn];

    }
}

- (void)didTransitionToState:(UITableViewCellStateMask)state{
    [super didTransitionToState:state];
    if (state != UITableViewCellStateShowingEditControlMask) {
        customEditBtn.alpha = 0;
    }
}

答案 1 :(得分:0)

如果其他人有这个问题: 您必须将editingAccessoryView上的UITablViewCell设置为您希望的自定义​​UIView

请参阅http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html

答案 2 :(得分:0)

试试这个。

UIButton *btnDelete = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
[btnDelete setImage:[UIImage imageNamed:@"delet.png"] forState:UIControlStateNormal];
[btnDelete addTarget:self action:@selector(deleteButtonClicked:event:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = btnDelete;