Search code examples
uitableviewswift4tvos

tvOS Programmatically changing focus of one UITableViewCell to another


i have a tvOS application where in im using custom tableview cells, lets say i have 3 tableviewcells. Now i need to make programmatically update the focus from one cell to another cell. i tried using the func selectRow(at indexPath: IndexPath?, animated: Bool, scrollPosition: UITableViewScrollPosition) where it doesnt select that cell(as the focus is still on the previous cell not on the one i desired) It scrolls to particular cell but doesnt change the focus

So is there any way in i can make the focus to programmatically move from one tableview cell to another?

My TableviewStucture is like below

  • First Cell: Normal TableviewCell)
  • Second Cell: UICollectionView inside a TableviewCell
  • Third Cell: Normal TableView Cell

I have the cell reference of destination cell to reach.

  • I need to make focus change from first cell to third cell,
  • or change focus from second cell to third cell, In case of second cell have a call back which gets called and have the index of the particular cell too (cellForRow(at indexPath: IndexPath) -> UITableViewCell?).

Thanks in advance.


Solution

  • This problem can be solved with using indexPathForPreferredFocusedView, which works just fine.