我有一个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;
}