我在 ViewDidLoad 方法中将 UILongPressGestureRecognizer 添加到表视图中。我添加了这个来检测代码中表格视图上的长按。但它永远不会奏效。在 ViewDidLoad 我添加了这段代码:
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 2.0; //seconds
lpgr.delegate = self;
[self.resultTableView addGestureRecognizer:lpgr];
[lpgr release];
我还添加了这个方法:
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:self.resultTableView];
NSIndexPath *indexPath = [self.resultTableView indexPathForRowAtPoint:p];
if (indexPath == nil) {
NSLog(@"long press on table view but not on a row");
}
else {
NSLog(@"long press on table view at row %d", indexPath.row);
}
}
请帮我解决这个问题?