【发布时间】:2019-07-25 01:21:28
【问题描述】:
我正在尝试在 uicollectionview imageview 单元格上加载核心数据二进制图像。当我转到集合视图控制器时,我在 theIssues.reloadData() 处收到错误消息“线程 1:致命错误:在隐式展开可选值时意外发现 nil”。如果我评论说屏幕只是黑色的。
class theCollection: UICollectionViewCell {
var backButton = UIButton()
@IBOutlet var dx : UIImageView!
}
class collectionVIEW: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{
var users = [Item]()
@IBOutlet var theIssues: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
users = AppDelegate.cdHandler.fetchObject()
theIssues.reloadData()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return users.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! theCollection
if let imageData = users[indexPath.row].image {
let coredataLoadedimage = UIImage(data: imageData)
cell.dx.image = coredataLoadedimage
//
}
return cell
}
}
我想要的只是获取二进制数据并显示在集合视图单元格图像视图上。
【问题讨论】:
-
添加异常断点,检查你的collectionView当时是否存在,检查你的cell是否正确出列
-
我添加了加载类时发生的情况的图片,希望对您有所帮助。 @AlexandrKolesnik
-
检查您的插座,似乎设置不正确
-
这就是有人告诉我的“因为你没有在任何地方的代码中设置它,并且它具有@IBOutlet 属性,它需要连接到你故事板上的 UICollectionView。”。我不知道那是什么意思。我通过拖放连接了按钮。我不知道我还能做什么。
-
@GustavoConde 我在上面的评论中添加了更多信息。
标签: swift uicollectionview uicollectionviewcell binary-data