【发布时间】:2016-11-17 07:43:41
【问题描述】:
这是我的代码
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 10;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"dfdsfs" forIndexPath:indexPath];
if (indexPath.item == 0) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 50)];
label.text=[NSString stringWithFormat:@"this is item %ld", (long)indexPath.item];
[cell.contentView addSubview:label];
cell.contentView.backgroundColor = [UIColor greenColor];
NSLog(@"im @ zero");
} else {
NSLog(@"im here %ld", (long)indexPath.item);
cell.contentView.backgroundColor = [UIColor yellowColor];
}
return cell;
}
我只想在索引路径零处添加标签。 我遇到了问题,因为标签也出现在其他索引路径中..
【问题讨论】:
标签: objective-c uilabel uicollectionviewcell