UITableView and new methods for tvOS

I am creating a tvOS test application. I have an image (outside the table), and when “focused” is not selected, I would like the image to change ... I know that the apple added a couple of methods for focusing. Can someone tell me which methods I would use to change this image when it is in “focus”? and how will i use it? Do I use this method:

- (BOOL)tableView:(UITableView *)tableView canFocusRowAtIndexPath:(NSIndexPath *)indexPath 

or I would use:

  - (void)tableView:(UITableView *)tableView didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator 

Please let me know! Thanks!

+5
source share
2 answers

If you want to change the image when the UITableViewCell gets focus, then you should use the second method.

  - (void)tableView:(UITableView *)tableView didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator { //You can get focused indexPath like below NSIndexPath *nextIndexPath = [context nextFocusedIndexPath]; // Now get image from data source, I will assume you have an images array UIImage *image = [_imagesArray objectAtIndex:nextIndexPath.row]; // Set image to image view, assuming you have a property imageView _imageView.image = image; } 
+7
source

I have not used a UITableView on tvOS, but it seems that if the element is outside of UITable, it will not be focused using table delegate methods. However, you can extend the UIImageView with a special class, and then override it as:

 - (void) didUpdateFocusInContext:(UIFocusUpdateContext *) context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator { if (context.nextFocusedView == self){ // change image self.image = focusedImage; } else { // restore view self.image = normalImage; } } - (void)canBecomeFocused { return YES; } 

If you have difficulty navigating an ImageView from a UITableView, you may need to use UIFocusGuide to connect the two areas.

0
source

Source: https://habr.com/ru/post/1232837/


All Articles