0

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

1)加载屏幕。附件视图图像在那里,按钮被隐藏。好的。

2)滑动一行。附件视图消失,按钮出现。好的。

3)向下滚动表格以显示更多单元格(我正在使用可重复使用的单元格)。所有新单元格都显示有附件视图,没有按钮。好,正如预期的那样。

4)向上滚动到我刷过的原始单元格。我看到了附件视图图像和按钮,如下所示: (

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

- (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;

有任何想法吗?

4

1 回答 1

0

你使用[self setSelected:NO animated:NO];in method(void)swipeCell 和 in method- (void)unswipeCell. 但 in (void)swipeCellit should be [self setSelected:YES animated:NO];

希望能帮助到你

于 2013-07-02T07:02:23.280 回答