Я хочу добавить жест Swipe в свою ячейку. Это работает нормально. Но проблема в том, когда я провожу пальцем по первой ячейке, но моя пятая ячейка также сильно ударить. Я знаю эту проблему indexpath. Пожалуйста, помогите. Но я застрял от нескольких часов.
let swipeLeft = UISwipeGestureRecognizer (target: self, action: #selector (self.handleLeftSwipe))
swipeLeft.direction = UISwipeGestureRecognizerDirection.left
table.addGestureRecognizer (swipeLeft)
let swipeLeftd = UISwipeGestureRecognizer(target: self, action: #selector(self.handleLeftSwipes))
swipeLeftd.direction = UISwipeGestureRecognizerDirection.right
table.addGestureRecognizer(swipeLeftd)
@objc func handleLeftSwipe(sender: UITapGestureRecognizer) {
print("rigt called")
let location = sender.location(in: self.table)
let indexPath = self.table.indexPathForRow(at: location)
let cell = self.table.cellForRow(at: indexPath!) as! TableViewCell
print("swipe")
cell.myView.frame.origin.x = -94
}
@objc func handleLeftSwipes(sender: UITapGestureRecognizer) {
print("labelSwipedLeft called")
let location = sender.location(in: self.table)
let indexPath = self.table.indexPathForRow(at: location)
let cell = self.table.cellForRow(at: indexPath!) as! TableViewCell
print("swipe")
cell.myView.frame.origin.x = 80
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "TableViewCell"
var cell: TableViewCell! = tableView.dequeueReusableCell(withIdentifier: identifier) as? TableViewCell
if cell == nil {
var nib : Array = Bundle.main.loadNibNamed("TableViewCell",owner: self,options: nil)!
cell = nib[2] as? TableViewCell
}
return cell!
}