superViewにtapGesture.isがあるときに、collectionViewがdidSelectItemAtIndexPathを呼び出さなかったのはなぜですか?
レスポンダーチェーンに従って "doGesture"が印刷されるのはなぜですか?superViewにジェスチャがあるときに、collectionViewはdidSelectItemAtIndexPathを呼び出さなかった
- initCollectionViewは、iPhoneでself.viewに
- クリック項目を
- addTapGestureをself.viewに追加します。
didSelectItemAtIndexPathを呼び出しません。
- (void)viewDidLoad { [super viewDidLoad]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; self.collectionView = [[MyCollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 100) collectionViewLayout:flowLayout]; [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"abc"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; [self.view addSubview:self.collectionView]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doGesture)]; tapGesture.delegate = self; [self.view addGestureRecognizer:tapGesture]; } - (void)doGesture { NSLog(@"%@",@"doGesture"); } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 100; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"%@",@"didSelectItemAtIndexPath"); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"abc" forIndexPath:indexPath]; if (indexPath.row %2==0) { cell.backgroundColor = [UIColor redColor]; } else{ cell.backgroundColor = [UIColor grayColor]; } return cell; }
"not did didCelectItemAtIndexPath" doGestureを呼び出しましたか? - 別の言い方をしてみましょう。 '[self.view addGestureRecognizer:tapGesture]'行を削除したとします。 _Now_セル選択は機能しますか? – matt
なぜcollectionViewにジェスチャーを追加していますか?フロー/機能要件は何ですか? –