私はシートマップを作成しています.すでに予約されている座席はほとんどなく、他の人は予約できるので、すでに予約されている座席と空席を異なる色で表示する必要があります. 以下は、選択したセルと選択解除したセルを表示するために使用しているコードですが、既に選択されている予約済みのセルを表示する方法です。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSLog(@"indexpath row:%d", indexPath.row);
int v;
NSString *cnt = [NSString stringWithFormat:@"%@",[arrSeats objectAtIndex:indexPath.section]];
v = [cnt intValue];
if(indexPath.item < v)
{
if(cell.selected){
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yelow_seat.png"]]; // highlight selection
}
else
{
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_seat.png"]]; // Default color
}
}else{
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blank_seat.png"]];
}
return cell;
}
以下は、各セクションの値を追加するために使用しようとしているコードです。配列がセクションの値を追加するたびに、それを辞書に追加してから配列をクリアし、次に配列が次のセクションの値を追加して辞書に入れますが、配列オブジェクトが削除されたときに辞書は値を保持していません。
arrStatus = arrSeatsStatus;
[seatsDict setObject:arrStatus forKey:[NSString stringWithFormat:@"%d",i]];
i++;
[arrSeatsStatus removeAllObjects];
すべての座席のステータスをオンまたはオフとして保持する配列を持っていますが、それを実装する方法がわかりません。以上をご案内します。前もって感謝します。