我有一个包含图像视图和标签的CollectionView单元。当我尝试设置任何图像或我的程序崩溃,这个误差范围内的标签中的文字:尝试访问已注册单元的成员时出现运行时错误
fatal error: unexpectedly found nil while unwrapping an Optional value
细胞是从UICollectionViewCell继承自定义类,以及出口已创建和链接故事板:
class CustomCell: UICollectionViewCell {
@IBOutlet var thumbnailImageView: UIImageView!
@IBOutlet var textLabel: UILabel!
}
我设置ImageView的有:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CustomCell
cell.thumbnailImageView.image = UIImage(named: "ss")
return cell
}
我本来以为有什么不对的图像文件的位置,所以我评论它,并试图改变标签的文字:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CustomCell
cell.textLabel.text = "Hello"
return cell
}
但这也导致了崩溃。什么会导致自定义单元格正确加载,但无法访问其任何成员?
编辑:在viewDidLoad中功能我注册了我的课是这样的:
self.collectionView?.registerClass(CustomCell.self, forCellWithReuseIdentifier: reuseIdentifier)
编辑:
你连接的网点? –
是的,我把它们中的每一个都连接到故事板 –
单元格是否为零?你检查了吗? –