After a long but all in vain search, I am unable to detect the double tap / touch event in my tableview , actually want to call the detail view on double tap on any TableViewCell
and in reality I don't even know how to do it at all .
This is my code so far…
In viewDidLoad
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[self.myTable addGestureRecognizer:tapGesture];
the handleTapGesture method is
- (void)handleTapGesture:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateRecognized) {
flag = true;
}
}
and finally on touching or tapping the cell of tableview the delegate method is
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (flag == true)
{
DetailInvoicing *detail = [[DetailInvoicing alloc] initWithNibName:@"DetailInvoicing" bundle:nil];
detail.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
detail.customerName = [customerArray objectAtIndex:indexPath.row];
[self presentViewController:detail animated:YES completion:nil];
}
}
If I remove this flag condition new view is called on just single touch. where am I wrong or is there any other way to do it .
Go to Settings > Accessibility > Touch, and tap Back Tap. Tap Double Tap or Triple Tap and choose an action. Double or triple tap on the back of your iPhone to trigger the action you set.
viewTop. addGestureRecognizer(singleTap) // Double Tap let doubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(PostDetailViewController. handleDoubleTap)) doubleTap. numberOfTapsRequired = 2 self.
Swift version: 5.6. Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section.
There is a simple method, without using UITapGestureRecognizer
nor implementing custom table view class.
@implementation MyTableViewController
NSTimeInterval lastClick;
NSIndexPath *lastIndexPath;
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSTimeInterval now = [[[NSDate alloc] init] timeIntervalSince1970];
if ((now - lastClick < 0.3) && [indexPath isEqual:lastIndexPath]) {
// Double tap here
NSLog(@"Double Tap!");
}
lastClick = now;
lastIndexPath = indexPath;
}
@end
It is just view lines of code.
Corrected For Swift 3.1
var lastClick: TimeInterval
var lastIndexPath: IndexPath? = nil
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let now: TimeInterval = Date().timeIntervalSince1970
if (now - lastClick < 0.3) &&
(lastIndexPath?.row == indexPath.row ) {
print("Double Tap!")
}
lastClick = now
lastIndexPath = indexPath
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With