コレクション ビュー プログラミング ガイドによると、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];
}
}
デリゲート アプローチの代わりにこのアプローチに欠点はありますか?