use*_*951 11 objective-c xcode5
断言失败 - [UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:]
我从IOS 7开始就遇到了这个错误.它在IOS 6中工作正常.
我环顾网络,发现了这个:
http://forums.xamarin.com/discussion/8233/ios-7-crash-in-collectionview
但是,解决方案没有意义
我想到了.我错误地使用了CollectionView.RegisterClassForCell.显然我应该在设置viewcontroller时使用CollectionView.RegisterNibForCell.这解决了问题.iOS 6必须更加宽容.
你能不能给我一个关于这个bug的提示
Symptomps:
我怀疑的代码是这样的:
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize sz = [BGCollectionViewCellImage defaultSize];
return sz;
}
Run Code Online (Sandbox Code Playgroud)
但它似乎太普通了.
sz只是100*120的CGSize
另一个是:
- (BGCollectionViewCellImage *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BGCollectionViewCellImage * cell = [[BGCollectionViewCellImage alloc]init];
Image * img= self.arImages[indexPath.row];
[cell setImg:img andIndex:indexPath.row+1];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
也许我应该使用像UITableViewCell那样的队列
我得到了另一个暗示.如果我试图将某些单元格出列,我得到了这个:
2013-10-14 21:18:34.346 domainname [24667:a0b] *由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使类型的视图出列:标识为BGCollectionViewCellImage的UICollectionElementKindCell - 必须注册一个nib或类用于标识符或连接故事板中的原型单元'* First throw call stack :(
看起来我先注册了一些东西.
Lir*_*ron 17
如果有人遇到这种情况,另一种可能性是你忘了return cell;在collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath方法的最后.
Tim*_*Tim 11
您需要使用UICollectionView类参考中提供的相关注册方法之一注册您的单元格
- (void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;
- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier;
Run Code Online (Sandbox Code Playgroud)
其中相关的一个只需要在每个实例中调用一次UICollectionView.
| 归档时间: |
|
| 查看次数: |
10728 次 |
| 最近记录: |