I am having a problem with UIcollectionView, and I think this is the problem that is currently causing the problem.
Ok, so I have a collection that loads objects from a class, which is updated very often, maybe every few seconds.
The first problem I encountered; it was that when I selected the cell and selected it, highlighting another cell below as a collection. My solution was to create an array of selected cells and run a loop through a new array to decide what to select.
Now the problem occurs when the data collection is rebooted. The cells continue to remain selected and appear as selected, but they do not change the registrations, so I can not deselect.
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection: (NSInteger)section { return [self.deviceList count]; } - (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView { return 1; } - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath { DeviceCollectionViewCell *cell = [self.deviceCollectionView dequeueReusableCellWithReuseIdentifier:@"DeviceCell" forIndexPath:indexPath]; if([self.deviceList count] > indexPath.row) { cell.device = [self.deviceList objectAtIndex:indexPath.row]; } if ([[self.deviceCollectionView indexPathsForSelectedItems] containsObject:indexPath]) { NSLog(@"does it ever?"); // cell.backgroundColor = [UIColor blueColor]; } for (TDDeviceParser *device in self.selectedDevices) { if ([cell.device.deviceTextRecord.serialNumber isEqualToString:device.deviceTextRecord.serialNumber]) { [cell setSelected:YES]; break; } else { [cell setSelected:NO]; } } return cell; } - (UICollectionReusableView *)collectionView: (UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *reusableview = nil; if (kind == UICollectionElementKindSectionHeader) { TitleHeaderForDeviceCollectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath]; reusableview = headerView; } else if (kind == UICollectionElementKindSectionFooter) { LogoFooterForDeviceCollectionView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath]; reusableview = footerView; } return reusableview; }
DTDev source share