iphone – 控制台错误:必须使用非零布局参数初始化UICollectionView

iphone – 控制台错误:必须使用非零布局参数初始化UICollectionView,第1张

概述我是UICollectionView的新手,我正在按照我在Youtube上找到的教程,但我遇到了一个我无法弄清楚的错误. 当我使用此代码运行应用程序时: -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(NSIntege 我是UICollectionVIEw的新手,我正在按照我在Youtube上找到的教程,但我遇到了一个我无法弄清楚的错误.

当我使用此代码运行应用程序时:

-(NSInteger)numberOfSectionsInCollectionVIEw:(UICollectionVIEw *)collectionVIEw {        return 1;    }    -(NSInteger)collectionVIEw:(UICollectionVIEw *)collectionVIEw numberOfItemsInSection:(NSInteger)section {        return [self.array count];    }    -(UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw cellForItemAtIndexPath:(NSIndexPath *)indexPath {        CollectionCell *aCell = (CollectionCell *)[collectionVIEw dequeueReusableCellWithReuseIDentifIEr:@"myCell" forIndexPath:indexPath];        aCell.Title.text = self.array[indexPath.row];        return aCell;    }    - (voID)vIEwDIDLoad    {        [super vIEwDIDLoad];        self.array = @[@"First",@"Second",@"Thirth",@"Fourth"];    }

而在.h:

@property (strong,nonatomic) NSArray *array;

控制台中,我收到以下错误:

Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: 'UICollectionVIEw must be initialized with a non-nil layout parameter'

我没有使用故事板,自定义了CollectionVIEw你可以在这里看到:

有没有人有任何想法,为什么我收到此错误?一切都是受欢迎的!

编辑:

- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    self.array = @[@"First",@"Fourth"];    [self.collectionVIEw registerClass:[UICollectionVIEwCell class] forCellWithReuseIDentifIEr:@"myCell"];    UICollectionVIEwFlowLayout *flow = [[UICollectionVIEwFlowLayout alloc] init];    [flow setItemSize:CGSizeMake(60,60)];    [flow setScrollDirection:UICollectionVIEwScrollDirectionVertical];    [self.collectionVIEw setCollectionVIEwLayout:flow];}
解决方法 注册uicollectionvIEwcell视图类时出错.要解决,请在代码中添加以下行:

[self.collectionVIEw registerClass:[UICollectionVIEwCell class] forCellWithReuseIDentifIEr:@"myCell"];
总结

以上是内存溢出为你收集整理的iphone – 控制台错误:必须使用非零布局参数初始化UICollectionView全部内容,希望文章能够帮你解决iphone – 控制台错误:必须使用非零布局参数初始化UICollectionView所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1000206.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存