[英]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. 将公共方法performSelectionAnimations添加到MyCollectionViewCell的定义中。 Then call it from collectionView:didSelectItemAtIndexPath:
然后从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. 注意,我已经调用了[cell setSelected:YES],因为UICollectionView应该已经处理了。
You must do it programmatically. 您必须以编程方式进行。 Look at :
看着 :
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CollectionViewPGforIOS.pdf#page18 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). 当您点击单元格时,突出显示状态变为YES,但是必须实现行为(即,单击时更改背景单元格)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.