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!
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.
dequeueReusableCell(withIdentifier:)Returns a reusable table-view cell object after locating it by its identifier.
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.
Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With