Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView and new methods for tvOS

I am creating a test tvOS app. I have an image (outside the tableview) and when "focused" NOT selected, I would like the image to change... I know that apple has added a couple methods for focus. Could someone tell me which methods I would use to change this image for when it is in "focus"? and how would I use it? Would I use this method:

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

or would I use:

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

Please let me know! Thank you!

like image 563
Jenel Ejercito Myers Avatar asked Oct 02 '15 20:10

Jenel Ejercito Myers


People also ask

What is UITableView?

UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want.

What is dequeueReusableCell?

dequeueReusableCell(withIdentifier:)Returns a reusable table-view cell object after locating it by its identifier.

What class does UITableView inherit from?

The appearance of the tableview is managed by UITableView class, which inherits UIScrollView. In tableview, the row is simulated by the object of the UITableViewCell class, which can be used to display the actual content.

What is UITableView delegate?

Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.


1 Answers

If you want to change image when UITableViewCell item get focus, then you should use 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;
}
like image 130
Adnan Aftab Avatar answered Oct 26 '22 08:10

Adnan Aftab