BBBBB
BBBBB

Reputation: 37

Why when my custom cells in CollectionView are clicked they do not get highlighted?

When I click they,the function of click(shch as show an alert or get into a new view) works fine but the appearance of the cell I clicked don't change.What I can do to make the cell I click get highlighted ?THX~

Upvotes: 0

Views: 693

Answers (2)

Pradhyuman sinh
Pradhyuman sinh

Reputation: 3928

Add a public method performSelectionAnimations to the definition of MyCollectionViewCell. Then call it from collectionView:didSelectItemAtIndexPath:

-(void)performSelectionAnimations {

...


...
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
MyCollectionViewCell *cell = (MyCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
[cell performSelectionAnimations];
}

Notice I've taken out the call to [cell setSelected:YES], since that should already be taken care of by the UICollectionView.

Upvotes: 1

RFG
RFG

Reputation: 2902

You must do it programmatically. Look at :

https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CollectionViewPGforIOS.pdf#page18

When you tap on the cell the highlight state change to YES, but you must implement de behaviour (i.e. change background cell on click).

Upvotes: 0

Related Questions