大佬教程收集整理的这篇文章主要介绍了iphone – 控制台错误:必须使用非零布局参数初始化UICollectionView,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我使用此代码运行应用程序时:
-(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]; }
以上是大佬教程为你收集整理的iphone – 控制台错误:必须使用非零布局参数初始化UICollectionView全部内容,希望文章能够帮你解决iphone – 控制台错误:必须使用非零布局参数初始化UICollectionView所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。