- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 UICollectionView
,其 header 的大小不为零。似乎每当调用 insertItemsAtIndexPaths
时,如果标题在屏幕上,程序就会崩溃并显示以下消息:
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])'
当 header 大小为零时,或者当 header 不在屏幕上时,调用 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, 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;
}
然后我实现了两个委托(delegate)方法:
- (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 给它一个 View
要实现标题部分,您必须实现以下数据源方法
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
关于当标题在屏幕上时,IOS UICollectionView insertItemsAtIndexPaths 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14972827/
我有一个无限加载collectionview - 添加新项目:insertItemsAtIndexPaths 但是每次我调用insertItemsAtIndexPaths滚动停止insertItems
在 UICollectionView 中,我尝试使用 performBatchUpdates:completion 对我的 GridView 执行更新。我的数据源数组是 self.results。 这
我正在使用 insertItemsAtIndexPaths,但我试图了解此函数如何影响我的索引路径的排序。 我有 1 个部分和多个项目(或行)。我正在使用 UICollectionView。 当我插入
我知道有各种各样与此相关的问题,但没有一个答案回答了这个问题。 无论如何,我有一个应该永远滚动的 UICollectionView,但我似乎无法让 insertItemsAtIndexPaths: 工
我有一个 UICollectionView,其 header 的大小不为零。似乎每当调用 insertItemsAtIndexPaths 时,如果标题在屏幕上,程序就会崩溃并显示以下消息: Termi
UICollectionView:我做错了。我只是不知道如何。 我的设置 我在装有 iOS 6.0.1 的 iPhone 4S 上运行它。 我的目标 我有一个 TableView ,其中一个部分专门用
我在 UICollectionView 上的自定义布局对象上遇到问题。插入项目时,NSInternalInconsistencyException被抛出: 2012-11-16 10:01:18.92
我正在使用 UICollectionsView insertItemsAtIndexPath 并且它非常烦人,以至于当我在 UICollectionView 上滚动然后它调用 insertItemsA
我正在开发一个应用程序,其中有一个无限滚动的图像 UICollectionView。当用户到达页面底部时,我查询下一页图像,获取新的 indexPaths,并使用 [collectionView in
好吧,我真的被困在这里了:/在 Apple 的 Collection View Programming Guide 中插入一个项目,它说有两个步骤: 更新数据源对象中的数据。 调用 Collectio
我将 UICollectionView 与 NSFetchedResultsController 结合使用。当我获取新数据时,我将它们放入 SQLite 数据库中,然后我的 frc 收到一个通知,它会
我是一名优秀的程序员,十分优秀!