【发布时间】:2013-01-16 05:14:26
【问题描述】:
我有一个由自定义 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;
}
【问题讨论】:
-
来自开发指南。如果单元格的 selectedBackgroundView 属性包含有效视图,则集合视图会在单元格突出显示或选中时显示该视图。
标签: ios objective-c uicollectionview