Objective c 无法在uicollectionview、uicollectionview的特定indexPath.row处设置单元格标题
在处理UICollectionView时,我正在从nib加载一个单元格,如下所示Objective c 无法在uicollectionview、uicollectionview的特定indexPath.row处设置单元格标题,objective-c,ios,uicollectionview,uicollectionviewcell,Objective C,Ios,Uicollectionview,Uicollectionviewcell,在处理UICollectionView时,我正在从nib加载一个单元格,如下所示 - (void)viewDidLoad { [super viewDidLoad]; /* Uncomment this block to use nib-based cells */ UINib *cellNib = [UINib nibWithNibName:@"NibCell" bundle:nil]; [self.collectionView registerNib:cell
- (void)viewDidLoad
{
[super viewDidLoad];
/* Uncomment this block to use nib-based cells */
UINib *cellNib = [UINib nibWithNibName:@"NibCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"];
// Configure layout
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
self.collectionView.contentInset = UIEdgeInsetsMake(10.0f, 0.0f, 10.0f, 0.0f);
[flowLayout setItemSize:CGSizeMake(300, 200)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[self.collectionView setCollectionViewLayout:flowLayout];
}
我的nib文件如下所示
- (void)viewDidLoad
{
[super viewDidLoad];
/* Uncomment this block to use nib-based cells */
UINib *cellNib = [UINib nibWithNibName:@"NibCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"];
// Configure layout
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
self.collectionView.contentInset = UIEdgeInsetsMake(10.0f, 0.0f, 10.0f, 0.0f);
[flowLayout setItemSize:CGSizeMake(300, 200)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[self.collectionView setCollectionViewLayout:flowLayout];
}
顶部标签用于显示单元格数量,中间标签用于显示特定文本
在方法cellForItemAtIndexPath中,我只想将文本设置为特定行的单元格(在本例中,我是在第1行执行此操作):
运行应用程序时,应用程序出现问题。不仅是第1行的单元格的标题标签
设置为这是第1行
,但也设置了第5行、第9行和第10行的标题标签:
如果有人知道我在中间做错了什么。请帮忙
“我的集合”包含1个部分和15行用于此部分。单元格被重用。当您向下滚动且单元格1不可见时,集合视图将使其再次可用。只需为所有单元格设置文本,例如
titleLabel.text = [NSString stringWithFormat:@"this is row %d", indexPath.row];
有人知道这种情况吗?是的,我就是这么做的。我必须重新设置标题