简体   繁体   中英

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

当我单击它们时,click(显示警报或进入新视图)的功能正常,但是我单击的单元格的外观没有改变。如何使我单击的单元格突出显示? THX〜

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.

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 (ie change background cell on click).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM