直接上代码:
NSString *firstCellID = @"firstCellID";
MyAlbumFirstCell *firstCell = [tableView dequeueReusableCellWithIdentifier:firstCellID];
if (firstCell == nil)
{
firstCell = [[MyAlbumFirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:firstCellID];
}
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(cellLongPress:)];
[firstCell addGestureRecognizer:longPressGesture];
return firstCell;
#pragma mark - cell长按手势触发的方法
- (void)cellLongPress:(UILongPressGestureRecognizer *)cellLongPress
{
if (cellLongPress.state == UIGestureRecognizerStateBegan)
{
CGPoint point = [cellLongPress locationInView:_tableView];
NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:point];
if (indexPath != nil)
{
NSLog(@"%ld", indexPath.row);
}
}
}