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?
Here is some relevant code:
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;
}
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;
}
As SAE points out you will have to manually do it in the cell on highlight. Easiest way I found is to use the tableview didHighlightRowAtIndexPath and didUnhighlightRowAtIndexPath methods which sets a bool "highlighted" in your UICollectionCell instance and then override that property in a subclassed UICollectionCell class. The beauty of this is that the animation is already there for you. You can also do the same in a UITableView/UITableViewCell situation.
So in your UICollectionView using the UICollectionViewDelegate method:
Then in your UICollectionViewCell subclass add this:
you can try this code :
and