cell.accessoryView图像出现时不应该只用于可重用单元格

时间:2013-07-02 06:53:51

标签: ios uitableview custom-cell accessoryview

我正在使用自定义单元格设置两个图像,一个accessoryView图像和一些自定义按钮。 accessoryView图像最初显示。当用户滑动行时,我隐藏了accessoryView图像并取消隐藏按钮。当用户'未擦除'(或点击其他地方)时,我隐藏按钮并显示accessoryView。这一切都很好,除非我执行以下操作:

1)加载屏幕。 accessoryView图像在那里,按钮被隐藏。好。

2)滑动一行。 accessoryView消失,按钮出现。好。

3)向下滚动表格以显示更多单元格(我正在使用可重复使用的单元格)。所有新单元格都显示为accessoryView而没有按钮。很好,正如所料。

4)向后滚动到我刷过的原始单元格。我看到accessoryView图像和这样的按钮:  (

这是一些代码: 在我的自定义单元格对象中,我有:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    if (selected)
    {
        self.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow-right-black.png"]];
        UIImage *selectedRowImage = [UIImage imageNamed:@"table-selectedcellbg-red-45px-stretch.png"];
        self.selectedBackgroundView = [[UIImageView alloc]initWithImage:[selectedRowImage resizableImageWithCapInsets:UIEdgeInsetsMake(selectedRowImage.size.height, selectedRowImage.size.width/2, selectedRowImage.size.height, selectedRowImage.size.width/2)]];
    }
    else
    {
        self.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow-right.png"]];
        self.selectedBackgroundView = [[UIImageView alloc]initWithImage:[[UIImage alloc]init]];
    }
}

- (void)swipeCell 
{
    [self setSelected:NO animated:NO];
    self.accessoryView = nil;

    swipeButtons.hidden = NO;
}
- (void)unswipeCell
{
    [self setSelected:NO animated:NO];
    self.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow-right.png"]];
    swipeButtons.hidden = YES; 
}

在我的cellForRowAtIndexPath中,我检查单元格是否被刷过:

if (self.indexPathSwipeButton != nil && self.indexPathSwipeButton.row == indexPath.row)
{
    [cell swipeCell];
}
else
{
    [cell unswipeCell];
}
return cell;

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您在方法[self setSelected:NO animated:NO];和方法(void)swipeCell中使用- (void)unswipeCell. 但在(void)swipeCell中,它应该是[self setSelected:YES animated:NO];

希望有所帮助