Duck
Duck

Reputation: 35953

iphone - discovering the UITableViewCell given the cell.imageView

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.

Upvotes: 0

Views: 284

Answers (2)

EmptyStack
EmptyStack

Reputation: 51374

In your handleSwipe: method, try the following code.

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

I guess this will work.

Upvotes: 1

donkim
donkim

Reputation: 13137

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.

Upvotes: 1

Related Questions