IOS UICollectionView选择问题

IOS UICollectionView选择问题,ios,uicollectionview,ios8,xcode6,Ios,Uicollectionview,Ios8,Xcode6,当用户点击UICollectionViewCell时,我的UICollectionView有一个奇怪的行为 在我的假设中,根据苹果文档,当用户点击UICollectionViewCell时,单元格应该高亮显示,然后被选中 但在我的应用程序中,当用户点击手机时,手机只会高亮显示,而不是选中 当用户在单元格上滑动时,只有在这种情况下,单元格才会被选中 请帮忙。使用Xcode 6 我使用框中的UICollectionView和自定义UICollectionViewCell类,它覆盖setSelecte

当用户点击
UICollectionViewCell
时,我的
UICollectionView
有一个奇怪的行为

在我的假设中,根据苹果文档,当用户点击
UICollectionViewCell
时,单元格应该高亮显示,然后被选中

但在我的应用程序中,当用户点击手机时,手机只会高亮显示,而不是选中

当用户在单元格上滑动时,只有在这种情况下,单元格才会被选中

请帮忙。使用Xcode 6

我使用框中的UICollectionView和自定义UICollectionViewCell类,它覆盖
setSelected
setHighlighted
。我已经实现了这些方法

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath 
但这只是为了检查


UPD:
我已经拍下了录像

还应提供以下代码:

**UICollectionViewController**
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"should");
    return YES;
}

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"highlighted");
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"select %@", indexPath);
    _selectedCategory = _source[(NSUInteger) indexPath.row];
//  _selectedNumber = [NSNumber numberWithInteger:category.id];
}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"deselect %@", indexPath);

    if (_selectedCategory) {
        _selectedCategory = nil;
    }

} 


默认情况下,
UICapgesutureRecognitor
防止将触摸事件传播到
UIView
。看

您可以通过取消选中IB中的“取消视图中的触摸”或按代码执行以下操作来禁用此功能:

UITapGestureRecognizer *recognizer = self.myTapGestureRecognizer;
recognizer.cancelsTouchesInView = NO;

确保在Overrided
setSelected:
setHilighted:
中调用
super
,并从
collectionView:shouldSelectItemAtIndexPath:
返回
YES
,当然我会这样做。将代码和视频添加到问题中因此,您的问题是
collectionView:shouldSelectItemAtIndexPath:
甚至没有被调用。您是否使用任何
UIgestureRecognitor
?我可以将您的评论标记为答案。我在整个视图上有一个
点击识别器
,这导致了这个问题。也许你有什么想法,如何在整个视图中保持
点击手势识别器
,同时允许在
UICollectionView
中进行选择,就像js中的
preventPropogation
一样,开箱即用,没有任何黑客攻击?
UITapGestureRecognizer *recognizer = self.myTapGestureRecognizer;
recognizer.cancelsTouchesInView = NO;