Dra*_*ior 9 uicollectionview uicollectionviewcell ios7 xcode5
我正在尝试在Xcode 5中开发我的应用程序并在iOS 7环境下进行调试.
我有一个自定义的UICollectionViewLayoutAttributes.
我打算在长按UICollectionViewCell后做一些事情,所以我重写了UICollectionViewCell.m中的方法
- (void)applyLayoutAttributes:(MyUICollectionViewLayoutAttributes *)layoutAttributes
{
[super applyLayoutAttributes:layoutAttributes];
if ([(MyUICollectionViewLayoutAttributes *)layoutAttributes isActived])
{
[self startShaking];
}
else
{
[self stopShaking];
}
}
Run Code Online (Sandbox Code Playgroud)
在iOS 6或更低版本中,- applyLayoutAttributes:在我调用下面的语句后调用.
UICollectionViewLayout *layout = (UICollectionViewLayout *)self.collectionView.collectionViewLayout;
[layout invalidateLayout];
Run Code Online (Sandbox Code Playgroud)
但是,在iOS 7中,即使重新加载CollectionView,也不会调用- applyLayoutAttributes:.
这是一个苹果稍后会修复的错误,或者我必须做些什么?
小智 23
在iOS 7中,您必须在UICollectionViewLayoutAttributes子类中覆盖isEqual:以比较您拥有的任何自定义属性.
isEqual的默认实现:不比较自定义属性,因此总是返回YES,这意味着永远不会调用-applyLayoutAttributes :.
试试这个:
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
}
if (!other || ![[other class] isEqual:[self class]]) {
return NO;
}
if ([((MyUICollectionViewLayoutAttributes *) other) isActived] != [self isActived]) {
return NO;
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3786 次 |
| 最近记录: |