¿Dónde resaltar UICollectionViewCell: delegado o celda?
De acuerdo con laVista de colección Guía de programación uno debe manejar el estado visual de los resaltados de la celda en elUICollectionViewDelegate
. Me gusta esto:
- (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];
}
Lo que no me gusta de este enfoque es que agrega lógica al delegado que es muy específico para la célula. De hecho,UICollectionViewCell
gestiona su estado resaltado de forma independiente, a través de lahighlighted
propiedad.
No anularíasetHighlighted:
¿Ser una solución más limpia, entonces?
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
if (highlighted) {
[self highlight];
} else {
[self unhighlight];
}
}
¿Existen desventajas para este enfoque en lugar del enfoque de delegado?