1

I want to add a cell that longPressed to indexPathforSelectedRow.. when I longPress a cell, I hope it would be added automatically in indexPathForSelectedRow... how can I do it?

This code is long press function:

func longPress(longPressGestureRecognizer: UILongPressGestureRecognizer) {

 if longPressGestureRecognizer.state == UIGestureRecognizerState.Ended {

    let touchPoint = longPressGestureRecognizer.locationInView(self.view)
    if let indexPath = tableView.indexPathForRowAtPoint(touchPoint) {
        let cellToDeSelect:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)! 
     //then how? 
    }

}

}
Kirsteins
  • 27,065
  • 8
  • 76
  • 78
shin
  • 11
  • 3

1 Answers1

0

Simply use:

if let indexPath = tableView.indexPathForRowAtPoint(touchPoint) {
    tableView.selectRowAtIndexPath(indexPath, animated: false, scrollPosition: .None)
}
Kirsteins
  • 27,065
  • 8
  • 76
  • 78
  • oh!! i am very grateful to you! actually i spent whole day to search a solution... but i never didn't find a solution. but you did.. thanks a lot!! ^^ – shin May 25 '16 at 07:33