我已經爲UICollectionView內的UIScrollView設置了UITapGestureRecognizer。我已經配置它來正確檢測點擊並觸發我寫的一個方法,但是如果我嘗試將選擇器設置爲collectionView:didSelectItemAtIndexPath:當單擊一個單元格時程序崩潰。iOS爲什麼不能從UITapGestureRecognizer調用方法collectionView:didSelectItemAtIndexPath:?
任何想法爲什麼這種情況?
這工作:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
- (void) tapped:(UIGestureRecognizer *)gesture{
//some code
}
這不起作用:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(collectionView:didSelectItemAtIndexPath:)];
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//some code
}