iOS UITapGestureRecognizer에서 collectionView : didSelectItemAtIndexPath : 메소드를 호출 할 수없는 이유는 무엇입니까?

양귀비

UICollectionView 내에서 UIScrollView에 대한 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
}
산투

당신이 작성한 코드,

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(collectionView:didSelectItemAtIndexPath:)];

선택자는 일반적으로 UITapGestureRecogniser객체 인 하나의 입력 인수가있는 단일 함수입니다 .

이렇게해야합니다.

-(void)clicked:(UIGestureRecogniser *)ges{

}

그러나 선택기가 적절하지 않게 사용했습니다.

위 코드를 아래 코드로 변경하십시오.

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clicked:)];
-(void)clicked:(UIgestureRecogniser *)ges{
    //use gesture to get get the indexPath, using CGPoint (locationInView). 
    NSIndexPath *indexPath = ...;
    [self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];

}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관