0

からすべてのアイテムを削除する方法indexPathSelectdItems。以下は、から配列に値を保存するために使用しているコードですがindexPathSelectedITems、セクションが変更され、配列が値を新鮮なものとして保存する必要がある場合は、配列をクリアする必要があります。しかし、またindexPathForSelectedItems追加しpreviousSelectedValuesます。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *seatV;
int cs;

NSString *secVal = [arrSeatSel objectAtIndex:indexPath.section];
NSArray *arrSplit = [secVal componentsSeparatedByString:@":"];
seatV = [arrSplit objectAtIndex:1];
cs = [seatV integerValue];

int v;
NSString *cnt = [NSString stringWithFormat:@"%@",[arrTot objectAtIndex:indexPath.section]];
v = [cnt intValue];



NSString *sect = [NSString stringWithFormat:@"%d", indexPath.section];

if(indexPath.item < v)
{
     if([sectionInfo count] < cs)
     {
         itemPaths = [self.collectionView indexPathsForSelectedItems];
         //NSMutableArray *array = [NSMutableArray array];
         //array = [self.collectionView indexPathsForSelectedItems];
         //sectionInfo = [self.collectionView indexPathsForSelectedItems];
         sectionInfo = [NSMutableArray arrayWithArray: [self.collectionView indexPathsForSelectedItems]];
         //[sectionInfo addObject:[[self.collectionView indexPathsForSelectedItems] lastObject]];
                    [selectedItemsInfo setObject:sectionInfo forKey:sect];
          cell=[self.collectionView cellForItemAtIndexPath:indexPath];
          cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yellow_seat.png"]];
          //sectionInfo1 = sectionInfo;
     }
     else
     {
          [self.collectionView deselectItemAtIndexPath:[NSIndexPath indexPathForItem:indexPath.row inSection:indexPath.section] animated:YES];
          [sectionInfo1 addObject:[selectedItemsInfo objectForKey:sect]];
          [selectedItemsInfo setObject:sectionInfo1 forKey:sect];
          [sectionInfo removeAllObjects];
     }
}     
else
{
      [self.collectionView deselectItemAtIndexPath:[NSIndexPath indexPathForItem:indexPath.row inSection:indexPath.section] animated:YES];
}

NSLog(@"section array:%@", sectionInfo);
NSLog(@"section array1:%@", sectionInfo1);
NSLog(@"selected seats dict:%@", selectedItemsInfo);
}

では、以前の値をクリアして、indexPathSelectedItems新しく選択した値のみを保持できるようにする方法は?

4

1 に答える 1