如何将长按的单元格添加到indexpathforSelectedRow?

时间:2016-05-25 03:35:34

标签: ios swift uitableview cell uilongpressgesturerecogni

我想添加一个longPressed到indexPathforSelectedRow的单元格。 当我longPress一个单元格时,我希望它会在indexPathForSelectedRow中自动添加...我该怎么办?

此代码为长按功能:

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? 
    }

}

}

1 个答案:

答案 0 :(得分:0)

只需使用:

if let indexPath = tableView.indexPathForRowAtPoint(touchPoint) {
    tableView.selectRowAtIndexPath(indexPath, animated: false, scrollPosition: .None)
}