UICollectionViewDelegate 的点击事件无效,使用 StoryBoard

我想给 CollectionViewCell 绑定【点击】行为的触发事件,但做不到。

使用 StoryBoard 在 HomeController 上放置了一个 Collection View,
里面有一个 Cell 模板。

随后在 HomeController:
1. 实现了 UICollectionViewDataSource 委托
2. 实现了 UICollectionViewDelegate 委托
3. 已将 CollectionView 绑定 dataSource 和 dalegate
4. 实现了 collectionView:didSelectItemAtIndexPath, 见如下代码:

@interface LRHomeViewController : UIViewController <UIScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"cell #%d was selected", indexPath.row);
    return;
}

控件以及动态元素都显示正常。但点击 Cell 无法触发事件。

请输入图片描述
请输入图片描述
请输入图片描述

阅读 21.2k
1 个回答

你的ScrollView下面有一个CollectionView,还有一个View, 那个View是干嘛用的?大小是多大? 是不是遮挡了CollectionView, 所以导致后者没法接受事件?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题