Search code examples
uitableviewtvos

tvOS UITableView cell focused


I'm searching for a callback function of UITableView when the row is focused for when I navigate with apple remote and press up or down to select the row (not when I press enter).

On iOS we have didSelectRowAtIndexPath thats called when user selects the row but I can't find the function that is called when user navigates in the UITableView.


Solution

  • You must implement this delegate method:

    - (void)tableView:(UITableView *)tableView didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
    {
         //this gives you the indexpath of the focused cell
         NSIndexPath *nextIndexPath = [context nextFocusedIndexPath];
    }
    

    then you can do whatever you want with it in that function