Iphone 基于类型具有不同图像的单元格:UICollectionView
我试图根据细胞的类型在细胞上设置不同的图像。每个部分都有不同类型的单元。至少有两种类型,如座位图中有座位,所以图例为可用座位、预订座位、禁用座位和选定座位。我不明白的是如何识别细胞并相应地分配给它们图像。我的座位总数加上残疾人的座位。这里是残疾人座位,例如,我总共有20个座位,在一行中我显示了9个座位,因此将生成三行,分别有9、9和2个座位,我已经完成到27,因此所有三行都有座位,这7个额外的座位是残疾人座位。我现在如何管理这些。如果有任何不清楚的地方,请随时询问 这就是我迄今为止所尝试的Iphone 基于类型具有不同图像的单元格:UICollectionView,iphone,ios,Iphone,Ios,我试图根据细胞的类型在细胞上设置不同的图像。每个部分都有不同类型的单元。至少有两种类型,如座位图中有座位,所以图例为可用座位、预订座位、禁用座位和选定座位。我不明白的是如何识别细胞并相应地分配给它们图像。我的座位总数加上残疾人的座位。这里是残疾人座位,例如,我总共有20个座位,在一行中我显示了9个座位,因此将生成三行,分别有9、9和2个座位,我已经完成到27,因此所有三行都有座位,这7个额外的座位是残疾人座位。我现在如何管理这些。如果有任何不清楚的地方,请随时询问 这就是我迄今为止所尝试的 -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSLog(@"vals count:%d", [arrSeats count]);
for(int i=0; i<[arrLevels count]; i++)
{
if(section == i)
{
int v;
NSString *cnt = [NSString stringWithFormat:@"%@",[arrTot objectAtIndex:i]];
v = [cnt intValue];
if(v<=9)
{
return 9;
}
else{
int numOfRow = v/9; //2
if(v % 9 > 0)
numOfRow +=1; //2+1 = 3
int c = numOfRow*9;
return c;
}
}
}
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
int v;
NSString *cnt = [NSString stringWithFormat:@"%@",[arrTot objectAtIndex:indexPath.section]];
v = [cnt intValue];
if(v < 9)
{
if(cell.selected){
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yellow_seat.png"]]; // highlight selection
}
else
{
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_s.png"]]; // Default color
}
}else{
int numOfRow = v/9; //2
if(v % 9 > 0)
numOfRow +=1; //2+1 = 3
int c = numOfRow*9;
int get = c-v;
for(int i=0; i<get; i++)
{
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blank_seat.png"]];
}
}
return cell;
}
-(NSInteger)collectionView:(UICollectionView*)collectionView项目编号section:(NSInteger)section
{
NSLog(@“VAL计数:%d,[ARR座位计数]);
对于(int i=0;i 0)
numorrow+=1;//2+1=3
int c=numorrow*9;
int-get=c-v;
对于(int i=0;iUIColoctionView),我们得到了给出单元节和项数的indexPath。因此,请检查indexPath.row。如果小于20,请检查cell.selected。如果大于20,则为空。我编写了一些代码。请检查正确的逻辑
int v;
NSString *cnt = [NSString stringWithFormat:@"%@",[arrTot objectAtIndex:indexPath.section]];
v = [cnt intValue];
if(indexPath.row < v)
{
if(v < 9)
{
if(cell.selected){
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yellow_seat.png"]]; // highlight selection
}
else
{
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_s.png"]]; // Default color
}
}
}
else
{
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blank_seat.png"]];
}
intv;
NSString*cnt=[NSString stringWithFormat:@“%@,[arrTot objectAtIndex:indexPath.section]];
v=[cnt intValue];
if(indexPath.row