在我的主视图控制器中,我有一个 UICollectionView (使用IB创建)。而且:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath: (NSIndexPath *)indexPath
{
NSLog(@"Cell clicked....%d",[indexPath row]);
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
ChildView *calendar = [[ChildView alloc] initWithDate:newDate];
calendar.delegate = self;
[cell.contentView addSubview:calendar];
return cell;
}
如果我触摸到子视图的边界之外,我就会得到这个事件。如果我触摸子视图所在的单元格内部,didSelectCellAtRowIndex
中不会捕获任何事件。
为什么呢?
答案 0 :(得分:3)
集合视图在内部处理其触摸,因此视图上的任何触摸处理程序或手势识别器都将优先。