ios - 为什么 UICollectionView 的 UICollectionViewCell

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

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

但是,我的理解是,当用户触摸单元格时,它应该突出显示(蓝色),然后当用户抬起手指时突出显示应该消失。这没有发生。有什么想法吗?

以下是一些相关代码:

在 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 中进行了描述。 .

关于ios - 为什么 UICollectionView 的 UICollectionViewCell 没有在用户触摸时突出显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14637031/

相关文章:

c - Objective C boolean 数组

ios - Xcode 8 中的单元测试失败

iphone - NSLocale 和国家名称

ios - 为什么我的 UIButton 的 "touch up inside"事件没有被调用?

objective-c - UIAlertController 延迟显示

objective-c - 核心数据 : error: Failed to call designa

iphone - 将长格式的 NSString 拆分为多行

ios - 显示 UIAlertController 的简单 App Delegate 方法(在 S

ios - 如何将 NSDate 转换为相对格式 "Today","Yesterday","a we

iphone - 滚动后检测 UITableView 中的当前顶部单元格