ios – UICollectionViewController以非零布局参数错误编程崩溃

ios – UICollectionViewController以非零布局参数错误编程崩溃,第1张

概述我正在以编程方式创建一个UICollectionViewController.不,我不想像每个教程那样使用IB和Storyboard.我只想使用普通代码. 这是我在viewDidLoad中的内容: // UICollectionView UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] 我正在以编程方式创建一个UICollectionVIEwController.不,我不想像每个教程那样使用IB和Storyboard.我只想使用普通代码.

这是我在vIEwDIDLoad中的内容:

// UICollectionVIEw    UICollectionVIEwFlowLayout *aFlowLayout = [[UICollectionVIEwFlowLayout alloc] init];    [aFlowLayout setItemSize:CGSizeMake(200,140)];    [aFlowLayout setScrollDirection:UICollectionVIEwScrollDirectionVertical];    self.collectionVIEw = [[UICollectionVIEw alloc] initWithFrame:self.vIEw.frame collectionVIEwLayout:aFlowLayout];    [self.collectionVIEw setDelegate:self];    [self.collectionVIEw setDataSource:self];    self.collectionVIEw.backgroundcolor = [UIcolor clearcolor];    [self.collectionVIEw setautoresizingMask:UIVIEwautoresizingFlexibleHeight | UIVIEwautoresizingFlexibleleftmargin | UIVIEwautoresizingFlexibleRightmargin | UIVIEwautoresizingFlexibleWIDth];    [self.collectionVIEw registerClass:[PUCImageGrIDCell class] forCellWithReuseIDentifIEr:CollectionVIEwCellIDentifIEr];

我已经实现了所需的委托方法,但仍然会收到此错误:

Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: 'UICollectionVIEw must be initialized with a non-nil layout parameter'
解决方法 这是我用来初始化 UICollectionViewController:
- (ID)initWithCollectionVIEwLayout:(UICollectionVIEwLayout *)layout

您不需要实例化集合视图,控制器将为您执行此 *** 作.调用此框后设置框架,或者您可以覆盖并设置内部框架:

- (ID)initWithCollectionVIEwLayout:(UICollectionVIEwLayout *)layout{     self = [super initWithCollectionVIEwLayout:layout];     if (self) {         // additional setup here if required.     }     return self;}

我更喜欢使用autolayout约束.

总结

以上是内存溢出为你收集整理的ios – UICollectionViewController以非零布局参数错误编程崩溃全部内容,希望文章能够帮你解决ios – UICollectionViewController以非零布局参数错误编程崩溃所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1108328.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存