我想添加一个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?
}
}
}
答案 0 :(得分:0)
只需使用:
if let indexPath = tableView.indexPathForRowAtPoint(touchPoint) {
tableView.selectRowAtIndexPath(indexPath, animated: false, scrollPosition: .None)
}