これは私のために働く。私はこのコードをUITableViewControllerで使用しています
-(void)viewDidLoad{
//Recognize long tap
UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
gestureRecognizer.minimumPressDuration = 1.0; //seconds
[self.view addGestureRecognizer:gestureRecognizer];
[gestureRecognizer release];
}
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer{
CGPoint p = [gestureRecognizer locationInView:self.view];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if (indexPath != nil) {
//Do something
}
}
出典
2012-04-22 20:30:32
Edu