2013-03-24 19 views
5

UIViewControllerには、UICollectionViewFlowLayoutを使用するUICollectionViewが含まれています。私はUIStoryboardで作成したプロトタイプのセルも使用しています。カスタムページングを作成したいので、- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffsetを使用しています。indexPathForItemAtPointは常にnilを返します

問題は、ポイントが明確にコレクションの内側にあっても、targetContentOffset(スクロールビューのスクロールバーが停止するポイント)に対応するindexPathを取得しようとするたびに、コレクションビューはnilを返しますcontentSizeを表示します。

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 
{ 
    NSIndexPath *indexPath = [_collectionView indexPathForItemAtPoint:(*targetContentOffset)]; 
    // Do something with indexPath  
} 

私は間違っていますか?

+0

を? '_collectionView'自体が最初にnilであるかどうかをチェックします。 – 7usam

+0

私はscrollView変数自体を使用しようとしましたが、結果は同じです。私はメソッドを呼び出すときにどちらもゼロではないということは肯定的です。 – DrMonkey68

答えて

0

collectionViewはtargetContentOffsetのindexPathをまだ認識していません。

あなたはこの位置にレイアウトされるアイテムの属性を与えるために、CollectionViewLayoutに問い合わせる必要があります。

このような何か試してください:あなたはIVARを使用しているのはなぜ

UICollectionViewLayoutAttributes *attribute = [_collectionView.collectionViewLayout layoutAttributesForElementsInRect:(CGRect){(*targetContentOffset).x, 0, 10, self.collectionView.bounds.size.height}][0]; 
関連する問題