-1

I have a problem. I want to animate my tableview when its reloading the rows but I need to at the indexPath which I don't have in the @IBAction function, and if I add an indexPath Parameter the addTarget function doesn't work.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "homeScreenCell", for: indexPath) as! PostTableViewCell

            cell.likesButton.tag = indexPath.row
            cell.likesButton.addTarget(self, action: #selector(HomeScreenTableView.likeButtonTapped(_:)), for: UIControlEvents.touchUpInside)

            cell.imagePost.image = UIImage(named: CoreDataManager.postArray[indexPath.row].image!)
            cell.likesLabel.text = "\(CoreDataManager.postArray[indexPath.row].likes)"
            return cell
        }

        @IBAction func likeButtonTapped(_ sender: UIButton) {

            let buttonRow = sender.tag

            print(CoreDataManager.postArray[buttonRow].likes)

            CoreDataManager.postArray[buttonRow].likes += 1

            CoreDataManager.saveContext()

            tableView.reloadRows(at:**I need indexPath here** , with: .automatic)

            }
        }

what should I do?

SwiftiSwift
  • 7,528
  • 9
  • 56
  • 96

1 Answers1

0

You already have it

 tableView.reloadRows(at:[IndexPath(row:sender.tag, section:0)], with: .automatic)
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87