2

SupplementaryViewsを使用してUICollectionViewを実装しようとしています。Nibファイルを使用して補足ビューを作成します。以下は、supplementaryViewを追加するためのレイアウトのメソッドです。

    NSMutableArray *attributesInRect = [[super layoutAttributesForElementsInRect:rect] mutableCopy];

NSLog(@"%@", attributesInRect);
if ([self.collectionView numberOfItemsInSection:0] > 1 && !self.selectedItem)
{
    if ([self.musicList count] > 0)
    {
        UICollectionViewLayoutAttributes *musicViewAttributes = [self layoutAttributesForSupplementaryViewOfKind:@"MusicView" atIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];

        musicViewAttributes.size = CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]), 150);
        musicViewAttributes.center = CGPointMake(musicViewAttributes.size.width/2, musicViewAttributes.size.height/2);
        musicViewAttributes.zIndex = 0;
        [attributesInRect addObject:musicViewAttributes];
    }
}
return attributesInRect;

ここでは、属性の配列(attributesInRect)のみに注意を払う必要はありません。これを行うと、補足がCollectionViewに適切に追加されます。

私の問題は、追加されたsupplementaryViewを取得することです。NSLogでは、supplementaryViewが配列にリストされていないことがわかります。この場合、新しいものを追加する前にその存在を確認することはできません。

ドキュメントで指定されている理由がよくわかりません。

戻り値セルとビューのレイアウト情報を表すUICollectionViewLayoutAttributesオブジェクトの配列。デフォルトの実装はnilを返します。

それによると、私のsupplementaryViewはその配列にあるはずです。

それについて何か考えはありますか?

4

0 に答える 0