2017-01-09 2 views
1

super UICollectionViewCell에 대한 사용자 정의 클래스를 만들었습니다.UICollectionView XCode 사용자 정의 셀

"포인터 유형이 일치하지 않습니다"(cellForItemAtIndexPath : indexPath] 반환 UICollectionView 셀) 지금은

MyCollectionViewCell *itemView = [self.collectionView cellForItemAtIndexPath:indexPath]; 

를 호출 할 때 경고를 얻을.

어떻게 수정합니까?

+3

MyCollectionViewCell의 기본 클래스는 무엇입니까? UICollectionViewCell이어야합니다. – raidfive

+0

위의 메서드에서 호출 할 함수는 무엇입니까 ?? –

답변

3

경고는 cellForItemAtIndexPath가 UICollecitonViewCell을 반환하기 때문입니다. 다음과 같이 MyCollectionViewCell로 캐스팅해야합니다.

MyCollectionViewCell *itemView = (MyCollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath]; 

경고를 처리해야합니다.

+0

매우 사실. 사용자 정의 셀을 사용하여 올바르게 작동하게하려면 캐스팅이 중요합니다. –

+0

감사합니다. 그것은 효과가 있었다. –