0

I have a UITableView inserted sideways (rotated 90 degrees) in a view. This table has images. I need to implement the swipe method in a cell to allow deleting it, but as the table is sideways, I cannot use the table default swipe delete mechanism, or the delete icon would appear sideways and worst, microscopic, because the table is small.

So, I have to implement my own swipe method for the cell.

To do so, I have added the UISwipeGestureRecognizer gesture recognizer to each cell's imageView. When this method fires, I receive the cell's imageView on the handle method.

So, when a swipe happens on a cell.imageView the method handleSwipe: is fired...

- (void) handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer { 

Inside this method I can easily get the cell.imageView, by doing [gestureRecognizer view], but how do I obtain a reference to the cell itself?

thanks.

2 Answers 2

1

In your handleSwipe: method, try the following code.

UIImageView *imgView = (UIImageView *) [gestureRecognizer view]; UITableViewCell *cell = (UITableViewCell *) [[imgView superview] superview]; 

I guess this will work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, you were almost there. Xcode was giving me this error: " "warning: incompatible Objective-C types initializing 'struct UIView *', expected 'struct UITableViewCell *'... I modified your last line to UITableViewCell *cell = (UITableViewCell *)[[imgView superview] superview]; and it worked. "
1

One way of doing this might be to subclass the UIImageView and add an index property to this subclass. Then you can call on that property to see which cell that UIImageView belonged to.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.