【发布时间】:2018-01-23 12:14:07
【问题描述】:
在view B 我有一个可以从图库中获取图像的图像视图。图片在coredata中存储为NSData
现在,如果我单击提交按钮并返回到view A,我有一个collectionview,我想在其中显示图像。如果我再次转到 view B 并添加另一张图片,请点击提交并返回到 view A 我应该会看到 2 张不同的图片。
但是当我返回时,我看到的是第一张图片两次,而不是 2 张不同的图片。但是当我再次运行该应用程序时,我会看到所有不同的图像
按要求...
在view A 的viewWillAppear 中,这就是我所做的……
//Fetching from Database
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "Customers2")
do {
customerDetails2 = try managedContext.fetch(fetchRequest as! NSFetchRequest<NSFetchRequestResult>) as! [Customers2]
for result in customerDetails2 {
if let imageData = result.value(forKey: "image") as? NSData {
}
}
collectionview2.reloadData()
} catch let error as NSError {
print("Could not fetch. \(error), \(error.userInfo)")
}
在视图 A 的 numberOfItemsInSection 中......
count1 = customerDetails2.count
在view A 中的cellForRowAtIndexPath…
let dfg = customerDetails2[indexPath.row]
let asd = dfg.image
if let image = UIImage(data: asd! as Data) {
imageArray.append(image)
cell1.customerImageView.image = imageArray[indexPath.row]
}
【问题讨论】:
-
imageArray.append(在cellForRowAtIndexPath内)闻起来很糟糕 -
好的..那么应该有什么而不是那个..?
-
但即使我已经完成了
imageArray.append(image)...
标签: ios swift uicollectionview