我正在使用UICollectionView
并使用RFQuiltLayout库。我正在动态分配numberOfSectionsInCollectionView
和numberOfItemsInSection
。现在,17个部分被分配到集合视图。但显示它时只显示一个部分。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"tableCell" forIndexPath:indexPath];
UILabel* label = (id)[cell viewWithTag:21];
if(!label) label=[[UILabel alloc] initWithFrame:CGRectMake(2, 0, cell.frame.size.width-4, cell.frame.size.height)];
label.backgroundColor=[UIColor grayColor];
label.tag=21;
label.textColor=[UIColor blackColor];
label.textAlignment = NSTextAlignmentCenter;
label.numberOfLines = 2;
[label setFont:[UIFont fontWithName:@"HelveticaNeue" size:11]];
[cell.contentView addSubview:label];
NSLog(@"total section assigned %ld",(long)collectionView.numberOfSections);
NSLog(@"current section %ld",(long)indexPath.section);
if (indexPath.section == 0) {
if (indexPath.row == 0) {
label.text = @"Category";
[label setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:11]];
label.backgroundColor = [UIColor colorWithRed:127/255.f green:151/255.f blue:201/255.f alpha:1];
}else if (indexPath.row == 1) {
label.text = @"Current";
[label setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:11]];
label.backgroundColor = [UIColor colorWithRed:255/255.f green:176/255.f blue:142/255.f alpha:1];
}
}else {
CrimeAnalysisTable *aTable = [self.tableDataArray objectAtIndex:indexPath.section - 1];
if (indexPath.row == 0) {
label.text = aTable.category;
}
}
[cell setAutoresizesSubviews:YES];
cell.backgroundColor=[UIColor whiteColor];
}
[cell setNeedsLayout];
return cell;
}
我使用上面的代码显示部分,但代码不在else部分
部分数量的NSLog
正在打印17
,而当前部分正在打印0
。但计数不会超过0
。