【问题标题】:UILabel in UICollectionViewCell is nillUICollectionViewCell 中的 UILabel 为 nill
【发布时间】:2015-05-29 01:20:09
【问题描述】:

我已经通过 xib 在 UICollectionViewCell 上添加了一个 UILabel。
我已经在课堂上制作了必要的对象并进行了适当的连接。
在 cellForItemAtIndexPath 方法中,我可以访问声明的 UILabel,但标签始终为 nill。
我可以通过编程方式向 Cell 添加背景颜色,但不能通过 Xib。我还可以通过编程方式添加标签并使用它。
但我不能通过 xib 对标签做任何事情。
我已经注册了 Cell 类和笔尖。
如果有人可以帮助我解决这个问题,那就太好了

cellforitem里面的代码sn-p-

static NSString *cellIdentifier = @"Cell";
VideoCellCollection *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.backgroundColor=[UIColor whiteColor];
[cell clearData];
VideoInfo *video=[dataArray objectAtIndex:indexPath.item];
cell.lblName.text=video.strFileName; 

return cell

viewdidload 中的代码

UINib *cellNib = [UINib nibWithNibName:@"VideoCellCollection" bundle:nil];

[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"Cell"];
[self.collectionView registerClass:[VideoCellCollection class] forCellWithReuseIdentifier:@"Cell"];

提前非常感谢

【问题讨论】:

  • 请贴一些 cellForItemAtIndexPath 的代码?
  • 你可以为我们发布一些想法。还有一件事是你使用标签通过获取标签的引用?

标签: ios objective-c uilabel uicollectionviewcell


【解决方案1】:

尝试删除[self.collectionView registerClass:[VideoCellCollection class] forCellWithReuseIdentifier:@"Cell"];

【讨论】:

  • 之前试过。不工作。我知道这应该可行。但这真的很奇怪。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 1970-01-01
相关资源
最近更新 更多