图片不显示在我的collectionviewcells中。 iOS(swift) [英] Images arent shown in my collectionviewcells. iOS(swift)

查看:142
本文介绍了图片不显示在我的collectionviewcells中。 iOS(swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,所有的图像,我从相机。它们保存在我的coreData中。如果用户拍摄新照片,照片将保存在核心数据中,然后用coreData图像替换正常的数组数据。所以如果我回到集合视图,只显示第一个和最后一个图像。当我打印图像[indexpath.item]出我得到的图像。但它们没有显示在细胞中。我有一个自定义类为单元格中的imageView和imageView有约束,所以图像不可能出在可见区域我想。
我期待着您的帮助解决这个问题。

I got an array with all the images i got from the camera. They are saved in my coreData. If a user takes a new photo, the photo will be saved in the core data and then i replace the normal array data with the coreData images. So if i go back to the collection view, only the first and the last image is shown. When i print the images[indexpath.item] out i got the images. But they arent shown in the cells. I have a custom class for the imageView in the cell and the imageView has constraints, so the image cant be out of the visible area i think. I look forward to solve this problem with your help. Thank you.

以下是相机捕捉的代码:

Here is the code from camera catch :

 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);
}

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

And here is the code were i create the cell :

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

这篇关于图片不显示在我的collectionviewcells中。 iOS(swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆