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?