2015-10-09 8 views
3

Я ищу функцию обратного вызова UITableView, когда строка сфокусирована, когда я перемещаюсь с удаленным яблоком и нажимаю вверх или вниз, чтобы выбрать строку (не когда я нажимаю клавишу ввода).tvOS UITableView ячейка сфокусирована

На iOS есть didSelectRowAtIndexPath, который вызывается, когда пользователь выбирает строку, но я не могу найти функцию, которая вызывается, когда пользователь переходит в UITableView.

ответ

14

Вы должны реализовать этот метод делегата:

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

, то вы можете делать все, что вы хотите с ним в этой функции

0

Только в случае, если вы хотите сделать что-то с последним выбранным, вы можете сделать что вот так

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]; 
Смежные вопросы