【发布时间】:2015-11-26 17:47:44
【问题描述】:
首先:我知道关于这个主题有成千上万个问题,并且肯定在其中一个问题中我的问题得到了解答。但经过数小时的搜索,我没有找到解决我问题的答案......
我有一个 CollectionViewController(在容器内)和一个 CollectionViewCell。在 Cell 里面有一个 imageView。必须使用 CollectionViewController 中的按钮更改 imageView 的图像。
这是我的代码:
class essenCell: UICollectionViewCell {
@IBOutlet weak var Bild: UIImageView!
}
(细胞)
class essenCollectionViewController: UICollectionViewController {
[...]
@IBAction func xyz(sender: UIButton!) {
//following: the line with the error (unexpectedly found nil while unwrapping an Optional value)
essenCell().Bild.image = UIImage(named: "erster")
}
}
(集合视图控制器)
首先我认为我可以将按钮连接到单元和控制器,这在理论上可行,但在我的特定情况下不起作用。 图像更改发生在指向 parentViewController 的 if-Loop 内(在我的 Controller 内)。因为我不能在 Cell 中使用这个引用,所以我需要在 Controller 中使用按钮功能。
请帮帮我!
【问题讨论】: