In the tableview i added long press gesture to each cell. I try to get the current position of long pressed cell. But i couldn' t achieve it. Here how i try to do
but here rectOfCellInSuperview's x, y, width and height is always 0. No matter which cell is long pressed. How can i get the cell's position in superview.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
...
cell.contentView.tag = indexPath.row;
UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(otherCellLongPressed:)];
[cell.contentView addGestureRecognizer:gesture];
}
Code:
- (void) otherCellLongPressed:(UILongPressGestureRecognizer *) gesture {
if (gesture.state == UIGestureRecognizerStateEnded) {
NSIndexPath *indexPath = [NSIndexPath indexPathWithIndex:gesture.view.tag];
CGRect rectOfCellInTableView = [self.mainTableView rectForRowAtIndexPath: indexPath];
CGRect rectOfCellInSuperview = [self.mainTableView convertRect: rectOfCellInTableView toView: self.mainTableView.superview];
}
}