0

I am using custom cells where I set two images, an accessoryView image and some custom buttons. The accessoryView image shows up initially. When the user swipes the row, i hide the accessoryView image and unhide the buttons. When the user 'unswipes' (or taps somewhere else), I hide the buttons and show the accessoryView. This all works fine, except when I do the following:

1)Load the screen. accessoryView image is there and buttons are hidden. Good.

2)Swipe a row. accessoryView disappears and buttons appear. Good.

3)Scroll down the table to reveal more cells (I'm using reusable cells). All new cells are shown with accessoryView and no buttons. Good, as expected.

4)Scroll back up to the original cell I swiped. I see both the accessoryView image and the buttons like this:  (

Here's some code: In my custom cell object, I have:

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

In my cellForRowAtIndexPath, I check to see if the cell was swiped:

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

Any ideas?

Jason
  • 1,787
  • 4
  • 29
  • 46

1 Answers1

0

You use [self setSelected:NO animated:NO]; in method (void)swipeCell and in method - (void)unswipeCell. But in (void)swipeCell it should be [self setSelected:YES animated:NO];.

Hope it helps

user2398911
  • 96
  • 1
  • 14
  • Hi user2398911, thanks for your reply. I don't think this is it. I don't want the cell to be selected, that changes the background to red and highlights everything. The cell should be unselected, with the accessoryView hidden. – Jason Jul 02 '13 at 07:31
  • self.accessoryView.hidden = YES; – user2398911 Jul 02 '13 at 08:07
  • This setSelected function seems to be called AFTER cellForRowAtIndexPath is called. But I'm not calling this. Is there a method I need to override? – Jason Jul 02 '13 at 09:06
  • The workaround is to add 'if(self.swipeButtons.hidden)' in the setSelected method...don't put up the arrow if the buttons are not hidden. Still don't know what's calling it in the first place tho... – Jason Jul 02 '13 at 09:11