Myślę, że możesz chcieć zachować wybraną komórkę z innym kolorem tła, prawda? Następnie spróbuj tego kodu.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.backgroundColor = [UIColor magentaColor];
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.backgroundColor = [UIColor cyanColor];
}
Po prostu przypisz inny kolor BG dla komórek o różnym statusie. Dodatkowo poniższy kod jest dokumentacją metod wyzwalania sekwencji, podczas gdy ktoś dotyka komórki collectionView. Dokumenty te można również znaleźć w pliku UICollectionView.h, części protokołu UICollectionViewDelegate.
// Methods for notification of selection/deselection and highlight/unhighlight events.
// The sequence of calls leading to selection from a user touch is:
//
// (when the touch begins)
// 1. -collectionView:shouldHighlightItemAtIndexPath:
// 2. -collectionView:didHighlightItemAtIndexPath:
//
// (when the touch lifts)
// 3. -collectionView:shouldSelectItemAtIndexPath: or -collectionView:shouldDeselectItemAtIndexPath:
// 4. -collectionView:didSelectItemAtIndexPath: or -collectionView:didDeselectItemAtIndexPath:
// 5. -collectionView:didUnhighlightItemAtIndexPath:
iosuicollectionviewuicollectionviewdelegate
szukałem tej odpowiedzi ... I zmieniał niestandardową siatkę do UICollectionView i Tableview skojarzonej widzenia. Implementacja obu metod pozwala na wybór, a następnie zmianę selekcji. Dzięki Steve, to mi się udało. –