您的位置:首页 > 产品设计 > UI/UE

UICollectionViewController使用,pushViewController弹出时

2015-02-12 11:27 363 查看
UICollectionViewController不同于其他viewcontroller,在使用过程中特别容易出现这种错误

UICollectionView must be initialized with a non-nil layout parameter

如果是这样(已经建立了一个UICollectionViewController的storyboard),这是因为你还没有关联上storyboard。

以下是国外一个论坛上面的解释:
- (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout


So you need to pass it a layout object. You don't show the code where you make a collection view, but I'm assuming
CollectionViewController
is
a
UICollectionViewController
subclass,
in which case you need to use this designated initialiser:
- (id)initWithCollectionViewLayout:(UICollectionViewLayout *)layout


Currently, you're using
init
.

In both cases you need to create and pass in a layout object when initalising.

If your collection view is held in the storyboard then you need to get it from the storyboard using
instantiateViewControllerWithIdentifier:
,
so your code above would read something like:
viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CollectionViewController"];


另外在使用UICollectionViewCell的时候自动会生成
static NSString *
const reuseIdentifier = @"Cell";这个变量注册时候无需更改,只在要使用的时候使用自定义标识即可。


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: