在UITableView上添加 swipe手势

  1. UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self   
  2.                                                                                   action:@selector(handleSwipeLeft:)];  
  3.     [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];  
  4.     [self.tableView addGestureRecognizer:recognizer];  
  5.     [recognizer release];  



  1. - (void)handleSwipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer  
  2. {  
  3.     //Get location of the swipe  
  4.     CGPoint location = [gestureRecognizer locationInView:self.tableView];  
  5.    
  6.     //Get the corresponding index path within the table view  
  7.     NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];  
  8.    
  9.     //Check if index path is valid  
  10.     if(indexPath)  
  11.     {  
  12.         //Get the cell out of the table view  
  13.         UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];  
  14.    
  15.         //Update the cell or model   
  16.         cell.accessoryType = UITableViewCellAccessoryCheckmark;  
  17.     }  
  18. }  

你可能感兴趣的:(ios,UITableView,手势,swipe)