選択したセルを配列に追加したいのですが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
)
配列arrLevels
はセクションの数です。配列itemPathsは選択したセルを追加しています。ここで問題は、選択したセルを追加しているセクションですが、各セクションにはセルの選択に独自の制限があります。あなたが私の主張を理解してくれることを願っています。簡単に言うと、レベル 1、2 などのさまざまなレベルのシート マップがあり、各レベルでは限られた座席を選択できます。次に、さまざまなレベルで選択された座席をさまざまな配列に追加する必要があります。