1

我想添加一个长按到 indexPathforSelectedRow 的单元格。当我长按一个单元格时,我希望它会自动添加到 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? 
    }

}

}
4

1 回答 1

0

只需使用:

if let indexPath = tableView.indexPathForRowAtPoint(touchPoint) {
    tableView.selectRowAtIndexPath(indexPath, animated: false, scrollPosition: .None)
}
于 2016-05-25T06:27:20.190 回答