我使用PSTCollectionView作为UICollectionView的替代品,以与iOS5(以及iOS6)兼容。 我正在使用情节提要创建我的根viewcontroller,然后以编程方式添加PSTCollecitonViewController。 这是代码:
- (void)viewDidLoad
{
[super viewDidLoad];
DRCollectionVC *collectionVC = [[DRCollectionVC alloc] initWithCollectionViewLayout:[PSTCollectionViewFlowLayout new]];
[collectionVC.collectionView setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self addChildViewController:collectionVC];
[collectionVC didMoveToParentViewController:self];
[self.view addSubview:collectionVC.collectionView];
}
我的DRCollectionVC是PSTCollectionViewController的子类。 DRCollectionVC的ViewDidLoad为:
- (void)viewDidLoad
{
[super viewDidLoad];
self.cellCount = 10;
[self.collectionView registerClass:[DRCell class] forCellWithReuseIdentifier:@"MY_CELL"];
}
上面的ViewDidLoad没有被调用。 我用UICollectionView尝试了类似的方法,这似乎很好。