2

私は現在、新しい UICollectionView のいくつかのデモ プロジェクトをいじっています。layoutAttributesForItemAtIndexPathこのデモのほとんどは、サブクラスでオーバーライドされます。ただし、その例のいずれかでメソッドが呼び出されることはありません。

Apple docs から、オーバーライドする必要があることを知っていますlayoutAttributesForItemAtIndexPath

このメソッドが呼び出される状況がわかりません。

この方法は特別な場合のためのものですか?

4

1 に答える 1

5

Apple doc でわかるかもしれませんが、サブクラスは layoutAttributesForElementsInRect と layoutAttributesForItemAtIndexPath の両方をオーバーライドする必要があります。

    layoutAttributesForElementsInRect:

    Returns the layout attributes for all of the cells and views in the specified rectangle.
    - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
    Parameters

    rect

        The rectangle (specified in the collection view’s coordinate system) containing the target views.

    Return Value

    An array of UICollectionViewLayoutAttributes objects representing the layout information for the cells and views. The default implementation returns nil.
    Discussion

    Subclasses must override this method and use it to return layout information for all items whose view intersects the specified rectangle. Your implementation should return attributes for all visual elements, including cells, supplementary views, and decoration views.

    When creating the layout attributes, always create an attributes object that represents the correct element type (cell, supplementary, or decoration). The collection view differentiates between attributes for each type and uses that information to make decisions about which views to create and how to manage them.
    Availability

        Available in iOS 6.0 and later.

    Declared In
    UICollectionViewLayout.h
于 2012-12-01T12:28:08.633 に答える