【发布时间】:2015-03-31 10:37:50
【问题描述】:
我正在尝试重新实现UICollectionView 看到的here 的不定式滚动。我缺少的东西:
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
对于整个项目,我使用了一个故事板和一个普通的UIViewController。在这个视图控制器上,我在 Interface Builder 中添加了一个 UICollectionView。我将集合视图的出口与我的视图控制器连接起来,并将数据源和委托方法再次设置到我的视图控制器。我还在Interface Builder中设置了UICollectionViewCell的自定义类和重用标识符。
所以一切都应该工作,但我只得到一个黑屏。我错过了什么?你可以下载整个项目here。
【问题讨论】:
标签: ios objective-c interface-builder uicollectionview infinite-scroll