我有一个集合视图,我subclassed集合视图单元格,所以我有重复的内容。如何访问不同方法中的uicollectionviewcell对象?
在我的集合视图类中,我使用这种方法来访问和设置我的单元格中的对象,例如设置一个贴在单元格上的标签?
- (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
?
* note,我想更新我的所有细胞,而不仅仅是一个细胞。
你想更新textLabel? – hoya21
@ hoya21多次,只要应用程序收到推送通知我想要一个方法来触发textLabel的更新,但是我不想做'[collectionView reloadData];'因为我有一个变换应用于我的将重置单元格大小(看起来不好)的单元格,这就是为什么我只想访问textLabel。 – Josh
对于重新加载UICollectionView的单元格,您可以参考此链接http://stackoverflow.com/a/20318136/3792386 –