我有一个UICollectionView,它由一个自定义的UICollectionViewCell子类组成.通过触发以下方法,该单元可以正确显示并正确响应用户的touch :

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

然而,我的理解是,当用户touch 电池时,它应该高亮显示(蓝色),然后当用户抬起手指时,高亮显示应该消失.这种情况不会发生.想知道为什么吗?

以下是一些相关代码:

在UICollectionView的数据源中:

@implementation SplitCheckViewCollection

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"ReceiptCellIdentifier";
    SplitCheckCollectionCell *cell = (SplitCheckCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.cellName.text = [NSString stringWithFormat:@"%@%i",@"#",indexPath.row+1];

    return cell;
}

在UICollectionViewCell的实现中:

@implementation SplitCheckCollectionCell

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"SplitCheckCollectionCell" owner:self options:nil];

        if ([arrayOfViews count] < 1) {
            return nil;
        }

        if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
            return nil;
        }

        self = [arrayOfViews objectAtIndex:0];    
    }
    return self;
}

推荐答案

该类只告诉您高亮显示状态,但不会更改视觉外观.你必须通过编程来完成,比如改变单元格的背景.

详情见CollectionView Programming Guide页.

Objective-c相关问答推荐

NSArray 添加元素

在 iOS 设备上本地存储图像

UIWebView 不会zoom 内容以适应

iPhone - 时区便利方法之间的差异

在 NSString 对象中查找子字符串

UITableView configureCellForDisplay:forIndexPath 中的断言失败:

在 Objective C 中使用 extern

AVAssetImageGenerator 提供旋转的图像

Select 具有受支持架构的目标以便在此设备上运行

每个 ivar 都必须是一个属性吗?

zoom UIView 及其所有子项

当 UIView 框架更改时,视图内的 AVPlayer 层不会调整大小

iOS 7 中的 UITextView 链接检测

如何将 tintColor 应用于 UIImage?

如何判断 WkWebView 是否在 Objective-C 中完成加载?

如何阻止 NSNotification 中的观察者调用两次?

UIScrollView contentSize 不起作用

哪个是正确的,nil 或 NULL,来标记没有 Objective-C 块?

更改导航栏的字体

Xcode 如何加载主情节提要?