UICollectionViewController使用,pushViewController弹出时
2015-02-12 11:27
363 查看
UICollectionViewController不同于其他viewcontroller,在使用过程中特别容易出现这种错误
UICollectionView must be initialized with a non-nil layout parameter
如果是这样(已经建立了一个UICollectionViewController的storyboard),这是因为你还没有关联上storyboard。
以下是国外一个论坛上面的解释:
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
a
in which case you need to use this designated initialiser:
Currently, you're using
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
so your code above would read something like:
另外在使用UICollectionViewCell的时候自动会生成
static NSString *
const reuseIdentifier = @"Cell";这个变量注册时候无需更改,只在要使用的时候使用自定义标识即可。
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
CollectionViewControlleris
a
UICollectionViewControllersubclass,
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";这个变量注册时候无需更改,只在要使用的时候使用自定义标识即可。
相关文章推荐
- pushViewController/presentModalViewController/addSubView区别及使用方法
- pushViewController/presentModalViewController/addSubView区别及使用方法
- iOS彩票项目--第四天,新特性界面搭建,UICollectionViewController的初次使用
- pushViewController/presentModalViewController/addSubView区别及使用方法
- Storyboard创建使用UICollectionViewController
- iOS开发之UITabBarController和UICollectionView的使用
- 如何在present出来的viewController里使用push方法
- iOS UICollectionViewController基本使用方法和简单的相册实现
- UICollectionViewController使用问题之UICollectionViewFlowLayout
- Storyboard创建使用UICollectionViewController
- 正确使用PresentModalViewController弹出框
- pushViewController/presentModalViewController/addSubView区别及使用方法(搬)
- iOS开发之UICollectionViewController系列(三) :使用UICollectionView自定义瀑布流
- UIWebView和UICollectionViewController的使用
- iOS开发之UITabBarController和UICollectionView的使用
- UICollectionViewController的使用
- 2015/10/21 UICollectionViewController 使用
- pushViewController/presentModalViewController/addSubView区别及使用方法
- 类似pushViewController的效果,但是是从底部弹出
- 使用模态视图导致pushViewController失效的解决方法