0

I am going from tableViewControllerOne to tableViewControllerTwo. When this happens, tableViewControllerTwo scrolls to a certain cell. This works well, however, I want the cell to be selected or "highlighted" after the scroll, and then become unselected/unhighlighted so it looks like the rest of the cells.

After my segue, I have this statement called tableView.scrollToRow(at: indexPath, at: .top, animated: true)

I tried doing this instead tableView.selectRow(at: indexPath, animated: true, scrollPosition: .top)

but the cell would remain selected. I also tried this tableView.selectRow(at: indexPath, animated: true, scrollPosition: .top) tableView.deselectRow(at: indexPath, animated: true) but they must both happen so quick that I never see the cell become selected.

rdk
  • 439
  • 3
  • 14

1 Answers1

0

You can try delaying the deselectRow function in a way I found here:

let when = DispatchTime.now() + 2 // change 2 to desired number of seconds
DispatchQueue.main.asyncAfter(deadline: when) {
   tableView.deselectRow(at: indexPath, animated: true)
}
JVS
  • 2,592
  • 3
  • 19
  • 31