- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试执行以下操作:
A) 关卡 1 已解锁(包含已解锁关卡的背景图片)。
B) 2-20 级被锁定(包含另一个背景图像)。当每个连续的级别完成时,它们将被解锁。
最初,当我运行该应用并转到我的 UICollectionView
时,一切看起来都不错。当我玩第 1 级并完成它时,我(通过核心数据)为一个名为 levelLocked
的 NSNumber
管理对象保存数字 0,现在属于第 2 级(0 表示已解锁,其他 3-20 级应该用 1 锁定)。
保存级别是锁定还是解锁的过程有效。但是当我返回到我的 UICollectionView
时,我没有看到级别 2 的物理变化(它仍然有锁的背景图像)。
此外,如果我在 UICollectionView
之前返回到 ViewController
,然后重新进入 UICollectionView
,应用程序会崩溃并显示错误:
*** Assertion failure in -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:],
我的单元格似乎没有正确更新(我不知道如何正确重新加载数据)。我确实为解锁和锁定级别类型注册了自定义 UICollectionViewCell
nib。我检查了所有的拼写(如果这是问题的话,它不会在第一次开始时起作用)。
这是细胞生成的代码。
static NSString *cellIdentifier = @"tortoiseCell";
static NSString *tortIdentifier = @"tortoiseLocked";
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *regular;
NSMutableArray *data = [self.dataArray objectAtIndex:indexPath.section];
NSString *cellData = [data objectAtIndex:indexPath.row];
NSMutableArray *ar = [self.lockArray objectAtIndex:indexPath.section];
NSNumber *arLocks = [ar objectAtIndex:indexPath.row];
if ([arLocks integerValue] == 0) {
TortoiseCell *cell = (TortoiseCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
[cell.buttonClick setTag:indexPath.row];
[cell.buttonClick setTitle:cellData forState:UIControlStateNormal];
[cell.buttonClick setBackgroundImage:[UIImage imageNamed:@"TortoiseLevels.png"]
forState:UIControlStateNormal];
[cell.buttonClick addTarget:self action:@selector(buttonPressedSoWhatNumber:)
forControlEvents:UIControlEventTouchUpInside];
cell.buttonClick.layer.masksToBounds = YES;
[cell addSubview:cell.buttonClick];
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
regular = cell;
} else if ([arLocks integerValue] == 1) {
TortoiseLocked *lockCell = (TortoiseLocked *)[collectionView dequeueReusableCellWithReuseIdentifier:tortIdentifier forIndexPath:indexPath];
[lockCell.tortoiseLock setTag:indexPath.row];
[lockCell.tortoiseLock setBackgroundImage:[UIImage imageNamed:@"TortoiseLock.png"]
forState:UIControlStateNormal];
lockCell.tortoiseLock.layer.masksToBounds = YES;
[lockCell addSubview:lockCell.tortoiseLock];
lockCell.layer.shouldRasterize = YES;
lockCell.layer.rasterizationScale = [UIScreen mainScreen].scale;
regular = lockCell;
}
return regular;
}
让我知道你的想法。我正在使用 iOS 8.1 和 XCode 7.1.2
最佳答案
如果你的数组中的值既不是 0 也不是 1,你的 cellForItemAtIndexPath
可以返回 nil
。我怀疑这就是正在发生的事情,然后 Collection View 有一个断言失败,因为你给它的是 nil 而不是单元格。
简单的修复方法是将 else if
更改为 else
,这将导致默认情况下“锁定”单元格。
您还可以添加一个新的 else
子句来记录错误,并使用它来尝试诊断为什么没有得到 0/1。
关于ios - UICollectionView *Assertion Failure* 未在 UICollectionViewCell 上应用属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40075500/
堆栈:Mac OS 10.15.6,Xcode 版本 12.0 (12A7209) 我有一个自行调整大小的收集单元。我覆盖 preferredLayoutAttributesFitting获得自我调整
我有一个 Storyboard,它是在 Xcode 6 中创建的,带有 Collection View ,并且单元格具有不同的大小类变化,例如不同的字体大小......( Storyboard中创建的
我有一个 UICollectionView,只有 1 个部分,该部分中有许多单元格。我启用了拖放行为(使用长按手势识别器,因为 UICollectionView 位于通用 UIViewControll
按照我的老问题here : How to add UIView inside a UITableViewCell Programmatically? 我想通过在这些 collectionViewCel
我将 UICollectionViewCell 与父 UICollectionViewCell 中的按钮一起使用: protocol DayCellDelegate { func button
例如,我有 10 个单元格的 UICollectionView。我想为选定的单元格添加边框,稍后,在选择另一个单元格时,想要删除以前的边框并为新的选定单元格添加边框。 我怎样才能做到这一点? 我已经试
我有一个 UICollectionViewCell(比如 UICollectionViewCell 1),单元格内有一个按钮和 UITextfields。连接到 (ViewController 1)
我在单个 UICollectionViewCell 内有 (3) UITextViews、(1) UITextField 和 (1) UILabel >。当文本换行到第二行时,在符合 UITextVi
我对 TableVieCell 中的 collectionView 有疑问。当我点击 collectionCell 时,didSelectItemAt 不会被调用。我在 collectionCell
我最近在我的 Storyboard中添加了一个 UICollectionView,它当前被另一个 View 插入 View ,这似乎工作正常但是,使用 Storyboard编辑器我将 View 设置为
我想在 UICollectionViewCell 上开始一些动画当用户点击一个单元格时。我的想法是在 didSelectItemAtIndexPath 中选择相应的单元格并触发动画。但是,这不起作用:
我可以通过使用手势识别器拖动它并简化新的 iOS 9 对重新排序的支持来重新排序 iOS 9 上的 UICollectionViewCells。 public func beginInteractiv
我正在开发一个应用程序,其中我在 UICollectionView 中实现了编辑模式。我正在尝试实现如下所示的内容: 当我单击编辑按钮时,相机按钮和眼睛按钮应隐藏,删除和重命名按钮应如下所示: 编辑后
我希望所有单元格之间以及屏幕边框和最近的单元格之间的间距相等。基本上是这样的。内部和周围的间距相等。 我设法通过设置这样的值在界面生成器中测试这一点。我将单元格大小设置为 110,最小间距设置为 0,
我已经设置了一个 UICollectionView,如下所示。我正在尝试设置自定义单元格高度,以便该集合在必须滚动之前适合屏幕上的 3 个单元格。但是,这种定制工作不起作用或似乎被忽略了。有谁知道我做
我在不使用 Storyboard的情况下以编程方式创建了 UICollectionView 和 UICollectionViewCell,但是发生了一些事情,我无法理解为什么。 BKPhotoCell
我正在寻找制作图片库。我希望我的图像全屏显示,但不确定这如何与自动布局一起使用。我知道有一种方法可以返回单元格的大小,但不知道我是否应该只获取屏幕大小并返回它,或者是否有使用自动布局的方法。 最佳答案
我有一个问题, 我有一个简单的 UICollectionView,其中包含从 Flickr 加载图像的静态 200 个单元格。 我的 CellForItemAtIndexPath 看起来像这样: -
以下代码是一个非常简单的程序,用于在 UICollectionView 中显示 1-10000 之间的数字。 .它在不滚动的情况下正确显示,但是如果您向下滚动并向后滚动 Collection View
这个问题在这里已经有了答案: UICollectionViewLayout Not working with UIImage in Swift 5 and Xcode 11 (2 个答案) 关闭 2
我是一名优秀的程序员,十分优秀!