objective c - Problems with UICollectionView - one selected cell implies other selections -


in collection view allowed multiple selection.

when tap item, system automatically select item not visible.

here's code:

-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview                   cellforitematindexpath:(nsindexpath *)indexpath  {     buttoncell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"buttoncell"                                                                   forindexpath:indexpath];      nsstring *title = self.ingredientsbook.names[indexpath.item];     cell.label.text = title;     return cell; }  -(void)collectionview:(uicollectionview *)collectionview         didselectitematindexpath:(nsindexpath *)indexpath {     self.searchbutton.enabled = yes;      buttoncell *cell = (buttoncell *)[collectionview cellforitematindexpath:indexpath];     cell.backgroundcolor = [uicolor whitecolor];     cell.label.textcolor = [uicolor bluecolor];      nsstring *name = self.ingredientsbook.names[indexpath.item];     [self.selectedingredientnames addobject:name]; } 

any suggestions?

it's because declares 2 times cell:

buttoncell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"buttoncell"                                                               forindexpath:indexpath]; 

and:

buttoncell *cell = (buttoncell *)[collectionview cellforitematindexpath:indexpath]; 

try declare cell in .h file , replace code write upper on code without class butoncell:

cell = [collectionview dequeuereusablecellwithreuseidentifier:@"buttoncell"                                                               forindexpath:indexpath]; 

and:

cell = (buttoncell *)[collectionview cellforitematindexpath:indexpath]; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -