我想添加选定的单元格UICollectionView
在数组中,按部分划分在不同的数组中,意味着每个部分有不同的数组。问题是部分的数量是动态的。下面是我的代码。
- (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];
sectionInfo = [NSMutableArray arrayWithArray: [self.collectionView indexPathsForSelectedItems]];
[selectedItemsInfo setObject:sectionInfo forKey:sect];
cell=[self.collectionView cellForItemAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yellow_seat.png"]];
}
else
{
[self.collectionView deselectItemAtIndexPath:[NSIndexPath indexPathForItem:indexPath.row inSection:indexPath.section] animated:YES];
[sectionInfo removeAllObjects];
}
[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);
}
数组arrSeatSel
正在获取部分的数量以及每个部分可以选择的座位数量。
description of arr seatsel:(
"Family:2",
"Gold:3"
)
这里的部分是 2 个,可以选择的单元格是 2 个。其他部分和所有情况下都是类似的。
arrTot
正在获取每个部分中的单元格总数
description of arrTot(
10,
10
)
array arrLevels
是部分的数量。数组 itemPaths 正在添加选定的单元格,这里的问题是,无论哪个部分都在添加选定的单元格,但每个部分都有自己的选择单元格限制。希望您明白我的意思,如果有任何不清楚的地方,请随意询问。
简而言之,我告诉你这里发生的事情是,有不同级别的座位图,级别1、级别2等。对于每个级别,你可以选择有限的座位,然后需要将不同级别的选定座位添加到不同的数组中。