2017-01-09 92 views
1

我爲超級UICollectionViewCell創建了自定義類。現在,當我打電話UICollectionView XCode自定義單元格

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

我得到一個警告:

「指針類型不匹配」,(cellForItemAtIndexPath:indexPath]返回UICollectionView細胞)。

我該如何解決?

+3

什麼是MyCollectionViewCell的基類?它應該是一個UICollectionViewCell。 – raidfive

+0

在上面調用哪個函數的方法? –

回答

3

警告是因爲cellForItemAtIndexPath返回一個UICollecitonViewCell。您必須將其投射爲MyCollectionViewCell,例如:

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

這應該照顧警告。

+0

非常真實。如果你使用自定義單元格,那麼爲了使它工作正常,投射很重要。 –

+0

謝謝。有效。 –

相關問題