【发布时间】:2014-10-02 12:24:01
【问题描述】:
在为 iOS7 编译时,我在 UICollectionView 上遇到了一个奇怪的错误,它在 iOS8 上运行良好。
我在 UICollectionViewCell 中有一个 UICollectionView,当我选择该 UICollectionViewCell 时,我正在增加该单元格的大小,因此其中的 UICollectionView 也应该增加其大小。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (collectionView == _collectionView){
NSLog(@"MainCell");
UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MenuCell" forIndexPath:indexPath];
UICollectionView * categoriesCollection = (UICollectionView*)[cell viewWithTag:2];
[categoriesCollection reloadData];
return cell;
}else{
NSLog(@"InsideCell");
UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CategoryCell" forIndexPath:indexPath];
cell.backgroundColor = CUSTOMCOLOR_BLACKGROUND_CELL_CATEGORY;
UILabel * cellLabel = (UILabel*)[cell viewWithTag:11];
cellLabel.text = @"TEST";
return cell;
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (collectionView == _collectionView){
return 4;
}else{
return 12;
}
}
在 iOS8 上查看。 https://www.dropbox.com/s/49xuy3ehhneuaki/Captura%20de%20pantalla%202014-10-02%2015.46.56.png
在 iOS7 上查看。它显示了 12 行的正确空间,但只显示了 1 行。而子collectionview的高度是30,但应该是360。https://www.dropbox.com/s/oncfyc42v7zjpds/Captura%20de%20pantalla%202014-10-02%2015.49.16.png
当使用 iOS8 SDK 或 iOS7 SDK 为 iOS8 编译时,会打印 12 次“InsideCell”,但是当我使用 iOS8 SDK for iOS7 时,它只会打印 4 次“InsideCell”,并且总是第 0 行。 这是苹果的错误吗? 谢谢
【问题讨论】:
-
if (collectionView == _collectionView)是什么意思?_collectionView是您自己设置的实例变量吗?发布设置它的代码。 -
是的,_collectionView 是这样的 IBOutlet 属性
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView; -
这个类是
UICollectionViewController的子类吗?如果是,您的属性声明可能与内部实现冲突。另外,您一直在比较collectionView和_collectionView有什么特别的原因吗?您是否在使用多个集合视图? -
不,这是一个普通的 UIViewController。主
_collectionView内的 UICollectionViewCell 有另一个 UICollectionView (categoriesCollection)。我添加了 2 张比较 iOS7 和 iOS8 的图片 -
尝试为所有嵌套集合视图的
tag属性赋值,并测试tag属性而不是检查与_collectionView的相等性。
标签: objective-c ios7 ios8 uicollectionview uicollectionviewlayout