I put this in cellForRowAtIndexPath
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(CalorieCountViewController.handleLongPress))
cell.addGestureRecognizer(longPress)
longPress.cancelsTouchesInView = true
let tapPress = UITapGestureRecognizer(target: self, action: #selector(CalorieCountViewController.handleTapPress))
cell.addGestureRecognizer(tapPress)
tapPress.cancelsTouchesInView = true
and put these(code below) outside of it, and removed didSelectRowAtIndexPath function entirely, use indexPathForSelectedRow instead to get which row user just selected.
func handleLongPress(sender: UILongPressGestureRecognizer){
let index = tableView.indexPathForSelectedRow!
doSomething(index)
}
func handleTapPress(sender: UITapGestureRecognizer){
let index = tableView.indexPathForSelectedRow!
doSomethingElse(index)
}
Turns out indexPathForSelectedRow returns nil, but I did select a row, and there is no "deselectRowAtIndexPath" anywhere in my code.