2015-10-02 8 views
5

私はテスト用tvOSアプリケーションを作成しています。私は画像を持っています(テーブルビューの外にあります)、 "フォーカスされていません"が選択されていない場合、画像が変わりたいと思います...リンゴがフォーカスのためにいくつかのメソッドを追加したことは分かります。誰かが、「フォーカス」にあるときにこの画像を変更するために使用する方法を教えてもらえますか?どのように使用するのですか?UITableViewとtvOSの新しいメソッド

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

か、私が使用します: 私は、このメソッドを使用します

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

私に知らせてください!ありがとうございました!

+0

tableViewCellがフォーカスを変更したときに画像を変更したいのですが...そうですか? –

答えて

7

UITableViewCell項目がフォーカスを取得したときに画像を変更したい場合は、2番目の方法を使用する必要があります。

- (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; 
} 
0

私はtvOS上のUITableViewを使用していないが、項目がuitableの外にある場合、それは表のデリゲートメソッドを使用してフォーカス可能ではないことと思われます。ただし、カスタムクラスでUIImageViewを拡張し、次にようにオーバーライドすることができます:あなたはのUITableViewからImageViewのに移動困難に遭遇した場合、次の2つの領域を埋めるためにUIFocusGuideを使用する必要があります

- (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; 
}