Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '*** setobjectForKey: object cannot be nil (key: <_UICollectionVIEwItemKey: 0xa38c910> Type = SV Kind = UICollectionElementKindSectionheader IndexPath = <NSIndexPath 0xa38c7c0> 2 indexes [0,0])'
当标头大小为零时,或者当标头不在屏幕上时,调用insertItemsAtIndexPaths可以正常工作.有谁知道如何解决这一问题?谢谢!
该类是UICollectionVIEwController的子类.这是与UICollectionVIEw相关的代码:
- (ID)init { // Collection vIEw layout UICollectionVIEwFlowLayout *layout = [[UICollectionVIEwFlowLayout alloc] init]; layout.itemSize = CGSizeMake(100,100); layout.headerReferenceSize = CGSizeMake(320,50); // left for the switch layout.minimumInteritemSpacing = 5; layout.minimumlinespacing = 5; layout.scrollDirection = UICollectionVIEwScrollDirectionVertical; layout.sectionInset = UIEdgeInsetsMake(5,5,5); if (self = [super initWithCollectionVIEwLayout:layout]) { // Collection vIEw setup [self.collectionVIEw registerClass:[UICollectionVIEwCell class] forCellWithReuseIDentifIEr:@"ID"]; self.collectionVIEw.frame = CGRectMake(0,-20,320,480-20-44-49); self.collectionVIEw.backgroundVIEw = nil; self.collectionVIEw.backgroundcolor = [UIcolor clearcolor]; ... } return self;}
然后我实现了两个委托方法:
- (NSInteger)collectionVIEw:(UICollectionVIEw *)collectionVIEw numberOfItemsInSection:(NSInteger)section { return [blogs count];}
和
- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEwArg cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionVIEwCell *cell = [collectionVIEwArg dequeueReusableCellWithReuseIDentifIEr:@"ID" forIndexPath:indexPath]; /* Some code to get blogVIEw */ [cell.contentVIEw addSubvIEw:blogVIEw]; return cell;}解决方法 问题是在日志中说标题不能为零.所以在那里给出一些有效的输入,你可以避免崩溃.
就像标题部分不需要输入一样,给它一个clearclolor视图
要实现标头部分,必须实现以下数据源方法
- (UICollectionReusableVIEw *)collectionVIEw:(UICollectionVIEw *)collectionVIEw vIEwForSupplementaryElementOfKind:(Nsstring *)kind atIndexPath:(NSIndexPath *)indexPath;
快乐编码:)
总结以上是内存溢出为你收集整理的当标题在屏幕上时,IOS UICollectionView insertItemsAtIndexPaths崩溃全部内容,希望文章能够帮你解决当标题在屏幕上时,IOS UICollectionView insertItemsAtIndexPaths崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)