我看过一些教程,用于将图片从照片库加载到tableView单元格。
他们这样做的方式有点奇怪,因为他们使用UIImagePickerController从照片库中获取图像,为其创建路径并将其保存到NS User Default或CoreData。
那么有没有办法从照片库中检索图像路径并直接加载它?
答案 0 :(得分:0)
您可以使用此代码。
class MyViewController {
func getImage() {
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = .PhotoLibrary
imagePickerController.delegate = self
self.presentViewController(imagePickerController, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
// Use image here.
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
答案 1 :(得分:0)
您可以尝试ALAssetRepresentation,我在Obj-C中使用相同的。