Iphone UITableViewCell自定义删除按钮

Iphone UITableViewCell自定义删除按钮,iphone,uitableview,Iphone,Uitableview,我想在uitableview单元格进入编辑模式时,在其上放置我自己的自定义删除按钮,类似于用于插入的“+”添加按钮,只是在“+”按钮所在的相同位置有一个红色的“x”。我该怎么做?如果其他人有这个问题: 您必须将uitableview单元格上的editingAccessoryView设置为您想要的自定义UIView 如果其他人有此问题,请参见: 您必须将uitableview单元格上的editingAccessoryView设置为您想要的自定义UIView 请参见试试这个 UIButton *bt

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

如果其他人有这个问题: 您必须将
uitableview单元格上的
editingAccessoryView
设置为您想要的自定义
UIView


如果其他人有此问题,请参见: 您必须将
uitableview单元格上的
editingAccessoryView
设置为您想要的自定义
UIView

请参见试试这个

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;
试试这个

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;

尝试使用cell
willTransitionOnState
实现它

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

尝试使用cell
willTransitionOnState
实现它

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

标准的“-”按钮有什么问题?标准的“-”按钮在左边,当点击它时,会弹出删除按钮。在编辑模式下,我想直接转到自定义删除按钮。我想把这个按钮放在右边的“+”按钮的位置。标准的“-”按钮怎么了?标准的“-”按钮在左边,当点击它时,它会激活删除按钮。在编辑模式下,我想直接转到自定义删除按钮。我希望这个按钮位于“+”按钮的右侧。
editingAccessoryView
用于“编辑”模式,通过在单元格或表格上调用
setEditing:animated
来启用该模式。这与滑动显示删除功能不同。如果您查阅UITableViewCell的
WillTransitionOnState:
方法的文档,您将看到“删除确认”与“显示编辑控件”是不同的模式。
editingAccessoryView
用于“编辑”模式,该模式通过在单元格或表格上调用
setEditing:animated
来启用。这与滑动显示删除功能不同。如果您在文档中查找UITableViewCell的
WillTransitionState:
方法,您将看到“删除确认”与“显示编辑控件”是不同的模式。AccessoryView不在tableViewCell的右侧吗?编辑控件在左侧。AccessoryView不是在tableViewCell的右侧吗?编辑控件位于左侧。