に補足フッターを追加しようとしていUICollectionView
ます。Apple のドキュメントによると、すべての適切なメソッドを実行しているように見えますが、何らかの理由で次のようになります。
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
…全然呼ばれない。
UICollectionReusableView
というクラスにサブクラス化しましたSmartActionFooterView
。
ではViewController
、ViewDidLoad
メソッドで、ビューを再利用識別子として登録および関連付けています。
[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
ただし、これは何も印刷していませんが、その理由については途方に暮れています。
これをすべてプログラムで行う必要があるという制約があります (ストーリーボードはありません)。
ありがとう!