2015-10-09 2 views
3

Je recherche une fonction de rappel de UITableView lorsque la ligne est focalisée lorsque je navigue avec apple remote et que j'appuie sur haut ou bas pour sélectionner la ligne (pas lorsque j'appuie sur enter).tvOS UITableView axé sur les cellules

Sur iOS nous avons didSelectRowAtIndexPath qui est appelée lorsque l'utilisateur sélectionne la ligne mais je ne trouve pas la fonction qui est appelée lorsque l'utilisateur navigue dans le UITableView.

Répondre

14

Vous devez mettre en œuvre cette méthode déléguée:

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

alors vous pouvez faire ce que vous voulez avec elle dans cette fonction

0

Juste au cas où vous voulez faire quelque chose avec dernier sélectionné, vous pouvez faire comme ça

NSIndexPath *nextIndexPath = [context nextFocusedIndexPath]; 
NSIndexPath *prevIndexPath = [context previouslyFocusedIndexPath]; 

UITableViewCell *nextCell = [self.tableView cellForRowAtIndexPath:nextIndexPath]; 
UILabel *nextTitleLabel = (UILabel *)[nextCell viewWithTag:100]; 
nextTitleLabel.textColor = [UIColor blackColor]; 

UITableViewCell *prevCell = [self.tableView cellForRowAtIndexPath:prevIndexPath]; 
UILabel *prevTitleLabel = (UILabel *)[prevCell viewWithTag:100]; 
prevTitleLabel.textColor = [UIColor whiteColor];