ios - 图像未显示在我的 Collection View 单元格中。 iOS(快速)

标签 ios swift image core-data collectionview

我得到了一个数组,其中包含从相机获得的所有图像。它们保存在我的 coreData 中。如果用户拍摄新照片,该照片将保存在核心数据中,然后我用 coreData 图像替换普通数组数据。因此,如果我返回到 Collection View ,则仅显示第一张和最后一张图像。当我打印图像[indexpath.item]时,我得到了图像。但它们没有显示在单元格中。我在单元格中为 imageView 有一个自定义类,并且 imageView 有约束,因此图像不能超出我认为的可见区域。 我期待在您的帮助下解决这个问题。谢谢。

这是相机捕获的代码:

 func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {




    photoImage.image = image

    print(images)
    addPhotoLabel.removeFromSuperview()
    if(isEdit == false)
    {

        let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
        let entinity = NSEntityDescription.entityForName("Image", inManagedObjectContext: context)

        let newImage = Image(entity: entinity!, insertIntoManagedObjectContext: context)
        newImage.image = UIImageJPEGRepresentation(image, 1)
        do {
            try context.save()
        } catch let error as NSError {
            print(error)
        }
        images.removeAll()
        let request = NSFetchRequest()
        request.entity = entinity
        let fetched = try? context.executeFetchRequest(request)
        if fetched != nil {
            let imagesS = fetched!.map { UIImage(data: ($0 as! Image).image!)}

            images.appendContentsOf(imagesS)

        }




    }
    self.dismissViewControllerAnimated(true, completion: nil);
}

这是我创建单元格的代码:

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
//1

let cell : FlickrPhotoCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! FlickrPhotoCell





if(searchBarActive == true)
{
    cell.nameLabel.text = researchResults[indexPath.item]
    cell.imageView.image = sFunc_imageFixOrientation(resultImages[indexPath.item])



}
else
{


cell.nameLabel.text = names[indexPath.item]
    let imageT : UIImage = images[indexPath.item]!

cell.imageView.image = images[indexPath.item]
print(images[indexPath.item])




}

cell.nameLabel.hidden = false

cell.frame.size = CGSizeMake(UIScreen.mainScreen().bounds.width/2  , UIScreen.mainScreen().bounds.width/2)

cell.imageView.frame = cell.frame



cell.backgroundColor = UIColor.clearColor()
cell.layer.borderColor = themeColor.CGColor
cell.layer.borderWidth = 4
cell.layer.cornerRadius = CGFloat(10.0)
cell.placeHolderName.frame.size = CGSize(width: cell.frame.width, height: cell.frame.height/4)







return cell

}

最佳答案

您可以尝试将 cell.imageView.frame = cell.frame 更改为 cell.imageView.frame.size = cell.frame.size

关于ios - 图像未显示在我的 Collection View 单元格中。 iOS(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38792898/

相关文章:

Swift indexPath 数组计算

ios - 在处理上一个时接收另一个远程通知操作

ios - UITextView 获取当前行

ios - 在 Swift 中使用协议(protocol)

iphone - 以编程方式关注 UITextView 不起作用

swift - 如何避免uitableview刷新

swift - MouseDown 事件阻止 NSCollectionView 委托(delegate)方法

wpf - 将图像添加到工具提示中

html - 图片在本地加载正常,但在网络服务器上加载不正常

javascript - 如何在加载图像时立即运行一些代码?