【发布时间】:2013-03-18 17:35:39
【问题描述】:
根据Collection View Programming Guide 应该处理UICollectionViewDelegate 中单元格突出显示的视觉状态。像这样:
- (void)collectionView:(PSUICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
MYCollectionViewCell *cell = (MYCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
[cell highlight];
}
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
MYCollectionViewCell *cell = (MYCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
[cell unhighlight];
}
我不喜欢这种方法的地方在于,它向委托中添加了非常特定于单元格的逻辑。事实上,UICollectionViewCell 通过highlighted 属性独立管理其突出显示状态。
那么,覆盖 setHighlighted: 不是更清洁的解决方案吗?
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
if (highlighted) {
[self highlight];
} else {
[self unhighlight];
}
}
这种方法比委托方法有什么缺点吗?
【问题讨论】:
标签: ios ios6 uicollectionview uicollectionviewcell