I have an UIButton in a UITableViewCell of an UITableView. The UIButton is hidden. When the user swipes left with his finger on a specific UITableViewCell the button show up.
I use this code to implement it and it is working but the button shows up in more than one uitableviewcells other than the one that the user swiped his finger!
- (void)cellSwiped:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
{
UIView *tappedview=[gestureRecognizer.view hitTest:[gestureRecognizer locationInView:gestureRecognizer.view] withEvent:nil];
UIView *contentview1=tappedview.superview;
UIView *viewwithtag4=[contentview1 viewWithTag:7009];
UIButton *button2=(UIButton *)viewwithtag4;
NSLog(@"swipe left detected");
[button2 setHidden:FALSE];
}
}
Any help appreciated! Thanks.
if the button is showing up in the wrong cells after scrolling it is because the tableCells are being reused by the tableView in order to enhance performance. i.e.
If you want to keep the button visible for a particular cell, you will have to do the following:
In the method that is called by the gestureRecognizer save the button’s state. You will have to determine the cell that has been swiped, then save that state probably in the class/model that your are filling the cell with. i.e your data source. For example, if your data source is an object in an array you could do something along the lines
Then in your cellForRowAtIndexPath method, you will have to set the button to be hidden or not depending on the state for that particular indexPath.
Good luck