如何获取在tvOS(AppleTV)上运行的UICollectionView上的单元格中的按钮以获得焦点?

时间:2015-09-14 02:04:50

标签: objective-c uicollectionview apple-tv tvos

这是我的基本代码。它在UICollectionView中显示了五个单元格(每个单元格中都有一个简单的按钮)。所有按钮都指向单个IBAction方法。这是Main.storyboard中的所有设置。

我无法让tvOS重点关注按钮。知道为什么吗?

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
    return cell;
}

- (IBAction)buttonAction
{
    // do stuff
}

@end

enter image description here

1 个答案:

答案 0 :(得分:3)

或者你可以

- (BOOL)collectionView:(UICollectionView *)collectionView canFocusItemAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}