0
Hier ist mein Codehinzufügen UILabel zu einem bestimmten indexPath in UICollectionView
- (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;
}
I-Label will bei Indexpfad Null nur hinzugefügt werden. Ich erhalte Problem, da das Label auch in anderen Indexpfade erscheint ..
danke für die Antwort –
@SunilKumar Gern geschehen! Hat es funktioniert? Wenn ja - bitte akzeptiere meine Antwort. – ppalancica