Skip to main content

Long press on UITableView



I would like to handle a long press on a UITableViewCell to print a "quick access menu". Does someone already did this ?





Particularly the gesture recognize on UITableView ?



Source: Tips4all

Comments

  1. First add the long press gesture recognizer to the table view:

    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
    initWithTarget:self action:@selector(handleLongPress:)];
    lpgr.minimumPressDuration = 2.0; //seconds
    lpgr.delegate = self;
    [self.myTableView addGestureRecognizer:lpgr];
    [lpgr release];


    Then in the gesture handler:

    -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
    {
    CGPoint p = [gestureRecognizer locationInView:self.myTableView];

    NSIndexPath *indexPath = [self.myTableView 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);
    }


    You have to be careful with this so that it doesn't interfere with the user's normal tapping of the cell and also note that handleLongPress may fire multiple times before user lifts their finger.

    ReplyDelete
  2. Use the UITouch timestamp property in touchesBegan to launch a timer or stop it when touchesEnded got fired

    ReplyDelete
  3. Looks to be more efficient to add the recognizer directly to the cell as shown here:
    http://www.cocoanetics.com/2010/08/taphold-for-tableview-cells-then-and-now/
    (scroll to the example at the bottom)

    ReplyDelete

Post a Comment

Popular posts from this blog

Wildcards in a hosts file

I want to setup my local development machine so that any requests for *.local are redirected to localhost . The idea is that as I develop multiple sites, I can just add vhosts to Apache called site1.local , site2.local etc, and have them all resolve to localhost , while Apache serves a different site accordingly.

CCNA4 FINAL 100/100

1. Refer to the exhibit. A network administrator is trying to configure a router to use SDM. After this configuration shown in the exhibit is applied, the SDM interface of the router is still not accessible. What is the cause of the problem? *The username and password are not configured correctly. The authentication method is not configured correctly. The HTTP timeout policy is not configured correctly. The vtys are not configured correctly. 2. Refer to the exhibit. Branch A has a non-Cisco router that is using IETF encapsulation and Branch B has a Cisco router. After the commands that are shown are entered, R1 and R2 fail to establish the PVC. The R2 LMI is Cisco, and the R1 LMI is ANSI. The LMI is successfully established at both locations. Why is the PVC failing? The PVC to R1 must be point-to-point. LMI types must match on each end of a PVC. The frame relay PVCs cannot be established between Cisco and non-Cisco routers. *The IETF parameter is missing from the frame-relay map ip 10....