【发布时间】:2015-07-10 12:31:54
【问题描述】:
我有一个集合视图,并且我对集合视图单元进行了子类化,所以我有重复的内容。
在我的集合视图类中,我使用此方法访问和设置单元格中的对象,例如设置附加到单元格的标签?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath];
//Configure Cell
//Set Name
DataManager *dm = [DataManager sharedInstance];
NSMutableArray *names = [dm objectForKey:@"nameArray"];
NSString *name = [names objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@", name]; //set cell here
return cell;
}
但是,我需要更新cell.textLabel,但我无法通过其他方法访问cell.textLabel?
我怎样才能通过除此之外的其他方法访问cell.textLabel?
*注意,我想更新我的所有单元格,而不仅仅是一个单元格。
【问题讨论】:
-
您想何时更新 textLabel?
-
@hoya21 多次,一旦应用程序收到推送通知,我想要一种方法来触发 textLabel 的更新,但是我不想这样做
[collectionView reloadData];因为我有一个转换应用于我的单元格,这将重置单元格大小(看起来很糟糕),这就是我只想访问 textLabel 的原因。 -
要重新加载 UICollectionview 的单个单元格,您可以参考此链接stackoverflow.com/a/20318136/3792386
标签: ios objective-c uicollectionview uicollectionviewcell