无法指定类型'[PHAsset]'的值来键入'UIImageView!'

时间:2016-04-26 20:52:21

标签: ios swift uiimageview uiimage phasset

  

无法指定'[PHAsset]'的值来输入'UIImageView!'

我在这里遇到问题:

enter image description here

更新的问题

    // CONVERT PHASSET TO UIIMAGE
func getAsset(asset: PHAsset) -> UIImage {
    let manager = PHImageManager.defaultManager()
    let option = PHImageRequestOptions()
    var image = UIImage()
    option.synchronous = true
    manager.requestImageForAsset(asset, targetSize: CGSize(width: 100.0, height: 100.0), contentMode: .AspectFit, options: option, resultHandler: {(result, info)->Void in
        image = result!
    })
    return image
}




func doneButtonDidPress(images: [UIImage]) {



    self.imagePickerController.dismissViewControllerAnimated(true, completion: nil)
    var selectedImg = imagePickerController.stack.assets

    getAsset(selectedImg)
    self.SelectImageView.image = UIImage(named: chosenImg)



    }

但是我得到的错误如下图所示

enter image description here

2 个答案:

答案 0 :(得分:0)

变量 selectedImage 的类型为 PHAsset

变量 self.backgroundImageView self.SelectImageView 的类型为 UIImageView

这两种类型不匹配,因此Swift不允许您进行分配。

要进行分配,您必须将PHAsset转换为UIImage ,然后将此 UIImage分配给UIImageView

答案 1 :(得分:0)

std::vector<double> fun() { return { 3.14, 2.7, 1.0 }; } [PHAsset]个对象的数组。要从数组中获取图像,请从所需的特定索引中获取PHAsset,然后使用requestImageForAsset:targetSize:contentMode:options:resultHandler:从资产中获取图像。