0

如何从indexPathSelectdItems. 下面是我用来将值保存到数组的代码indexPathSelectedITems,但是当部分更改时需要清除数组,并且数组应该将值保存为新的。但也indexPathForSelectedItemspreviousSelectedValues

- (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

0

尝试根据您的要求使用此代码。

[self deleteItemsFromDataSourceAtIndexPaths:selectedItemsIndexPaths];

或者

[self.collectionView deleteItemsAtIndexPaths:selectedItemsIndexPaths];
于 2013-05-31T05:42:19.900 回答