0

に補足フッターを追加しようとしていUICollectionViewます。Apple のドキュメントによると、すべての適切なメソッドを実行しているように見えますが、何らかの理由で次のようになります。

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

…全然呼ばれない。

UICollectionReusableViewというクラスにサブクラス化しましたSmartActionFooterView

ではViewControllerViewDidLoadメソッドで、ビューを再利用識別子として登録および関連付けています。

    [self.collectionView registerClass:[SmartActionFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView"];

そして、UICollectionFlowDelegateメソッドをオーバーライドします...

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
 referenceSizeForFooterInSection:(NSInteger)section
{
    NSLog(@"sizing footer");
    return CGSizeMake(300,100);
}

これNSLogがプリントアウトです。

私はそれからUICollectionViewDataSourceメソッドを打っています...

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{

NSLog(@"Something is happening with the footer...");
SmartActionFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView" forIndexPath:indexPath];

footerView.backgroundColor = [UIColor yellowColor];

return footerView;
}

NSLogただし、これは何も印刷していませんが、その理由については途方に暮れています。

これをすべてプログラムで行う必要があるという制約があります (ストーリーボードはありません)。

ありがとう!

4

2 に答える 2

0

問題が見つかりました。

私は UICollectionViewFlowLayout をサブクラス化し、間違って呼び出していました:

layoutAttributesForSupplementaryViewOfKind:atIndexPath

上記のサブクラスで適切に。このメソッドの呼び出しは、次の場所で行う必要があります。

layoutAttributesForElementsInRect:

属性は変更可能な配列に渡されます。

ここのドキュメントの私の理解から。View Controller でフッターを作成およびデキューする方法は UICollectionViewDataSource プロトコルの一部ですが、データソースは最初に UICollectionViewFlowLayout をチェックして、作成する必要があるオブジェクトを確認します。

于 2013-09-06T13:08:34.313 に答える