我正在尝试重新实现无限滚动的UICollectionView
,可以在这里看到。我发现缺少以下内容:
ViewController.h:
@interface ViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate>
@end
DataCell.h:
@interface DataCell : UICollectionViewCell
@property (nonatomic, strong) UILabel *label;
@end
DataCell.m:
#import "DataCell.h"
@implementation DataCell
-(instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if(self){
self.label = [[UILabel alloc] initWithFrame:self.bounds];
self.autoresizesSubviews = YES;
self.label.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
self.label.textAlignment = NSTextAlignmentCenter;
self.label.adjustsFontSizeToFitWidth = YES;
[self addSubview:self.label];
}
return self;
}
@end
CustomCollectionView.h:
@interface CustomCollectionView : UICollectionView
@end
整个项目我使用了一个storyboard和一个普通的UIViewController
。在这个视图控制器上,我在Interface Builder中添加了一个UICollectionView
。我将集合视图的出口与我的视图控制器连接,并再次设置数据源和委托方法。我还在Interface Builder中设置了UICollectionViewCell
的自定义类和重用标识符。所以一切都应该正常工作,但我只得到一个黑屏。我漏掉了什么?你可以在此处下载整个项目:here。
collectionView.backgroundColor = [UIColor clearColor];
和collectionView.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
。 - highboi