为什么UICollectionView的UICollectionViewCell没有突出显示用户触摸? [英] Why UICollectionView's UICollectionViewCell is not highlighting on user touch?

查看:63
本文介绍了为什么UICollectionView的UICollectionViewCell没有突出显示用户触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UICollectionView,它由一个自定义的UICollectionViewCell子类组成。单元格正确显示并通过触发此方法正确响应用户的触摸:

I have a UICollectionView that is made up of a custom UICollectionViewCell subclass. The cell's are displaying correctly and are responding correctly to user's touches by firing this method:

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

然而,我理解当用户触摸时单元格,它应该突出显示(蓝色),然后当用户抬起手指时,高光应该消失。这不会发生。有关为什么的任何想法?

However, I am of the understanding that when a user touches the cell, it should highlight (in blue) and then the highlight should go away when the user lifts their finger. This is not happening. Any thoughts on why?

以下是一些相关代码:

在UICollectionView的数据源中:

In the UICollectionView's datasource:

@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的实现中:

In the UICollectionViewCell's implementation:

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


推荐答案

该课程仅告诉您突出显示状态,但不会改变视觉外观。您必须以编程方式执行此操作,例如:更改单元格的背景。

The class only tells you about the highlight state, but doesn't change the visual appearance. You'll have to do it programmatically by e.g. changing the background of the cell.

详细信息在 CollectionView编程指南

这篇关于为什么UICollectionView的UICollectionViewCell没有突出显示用户触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆