diese Zeile für Sie eine globale arr erstellen müssen ausgewählte indexPath in Ihre h-Datei zu halten
NSMutable *arrSelectedIndex;
In Ihrem didSelectItemAtIndexPath müssen Sie den folgenden Code schreiben.
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self selectDeselectIndexpath:indexPath];
[collectionView reloadData];
}
// this method is used to toggle between selection and deselection
-(void) selectDeselectIndexpath : (NSIndexPath *) indexPath{
for (int i=0; i < arrSelectedIndex.count; i++) {
NSIndexPath *index = [arrSelectedIndex objectAtIndex:i];
if (index.row == indexPath.row && index.section == indexPath.section) {
[arrSelectedIndex removeObject:index];
return ;
}
}
[arrSelectedIndex addObject:indexPath];
}
// this method is used to select any indexPath
-(void) selectIndexpath : (NSIndexPath *) indexPath{
for (int i=0; i < arrSelectedIndex.count; i++) {
NSIndexPath *index = [arrSelectedIndex objectAtIndex:i];
if (index.row == indexPath.row && index.section == indexPath.section) {
return ; // This means indexPath already selected
}
}
[arrSelectedIndex addObject:indexPath];
}
// this method is used to deselect any indexPath
-(void) deselectIndexpath : (NSIndexPath *) indexPath{
for (int i=0; i < arrSelectedIndex.count; i++) {
NSIndexPath *index = [arrSelectedIndex objectAtIndex:i];
if (index.row == indexPath.row && index.section == indexPath.section) {
[arrSelectedIndex removeObject:index];
return ; // Indexpath found and remove from array
}
}
// Reaching over here means this indexpath not selected;
}
Sie können als jede der oben beschriebenen Methode verwenden pro Sie benötigen.
Geben Sie den entsprechenden Code ein – Sofeda
Das ist wegen 'dequeueReusingCell', müssen Sie den Wert in jeder Zelle aktualisieren sowie verfolgen Sie Ihre ausgewählten IndexPath und markieren Sie als ausgewählt/normal entsprechend in' CellForRowAtIndexPath' Methode. –
Ich habe 20 Abschnitte wie diese ... gibt es eine Möglichkeit, durch diese @DipenPanchasara –