【发布时间】:2015-02-08 14:11:32
【问题描述】:
UICollectionViewCell 中有一个标签。 我在 UICollectionView 中制作了 6 个单元格,并为每个单元格中的标签分配了一个数字 (1-6)。 我调用 [UICollectionView reloadData] 并期望标签中的数字相同。 但是,调用 cellForItemAtIndexPathas 时会更改标签值,例如“1 3 1 3 1 3”。 似乎 UICollectionViewCell 已重新定位在 cellForItemAtIndexPathas 中。
有什么办法可以保存吗?
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
InfoCollectionViewCell *infoCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"InfoCell" forIndexPath:indexPath];
[infoCell.cellText setText:[infoCell.cellText.text stringByAppendingString:[NSString stringWithFormat:@"%d\n",indexPath.row]]];
return infoCell;
}
【问题讨论】:
-
这些单元格通常是在
cellForItemAtIndexPath中“制作”的,通常是通过调用dequeueReusableCellWithReuseIdentifier来完成的,但我从这个问题中得到了感觉,这不是你在做什么。如果不查看代码,很难了解那里可能出了什么问题。我建议在您的问题中添加一些示例代码 - 会更容易回答。 -
附上我的代码。我希望 infoCell.cellText 标签在每次调用时都是相同的。但是,这是随机更改的。
标签: objective-c uicollectionview