【发布时间】:2015-09-19 20:13:48
【问题描述】:
我有一个UIImagePickerController,它允许用户将图像添加到 localDatastore:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let pickedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
print("photo picked!")
//self.collectionView?.reloadData()
//try writing to parse local datastore?
let imageObject = PFObject(className: "imagePicked")
imageObject["theImg"] = PFFile(data: UIImageJPEGRepresentation(pickedImage, 0.1)!)
imageObject["id"] = "123321"
imageObject.pinInBackgroundWithName("imgs") { (success, error) -> Void in
if error == nil{
print("Object pinned!")
self.collectionView?.reloadData()
} else {
print(error)
}
}
self.dismissViewControllerAnimated(true) { () -> Void in
self.collectionView?.reloadData()
}
}
然后在 viewDidLoad 中,我将 localDatastore 中的所有对象附加到一个数组中 -
let query = PFQuery(className: "imagePicked")
query.fromLocalDatastore()
query.fromPinWithName("imgs")
// Put all of the objects found in an array
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if error == nil {
let objects = objects as! AnyObject
for object in objects as! [AnyObject] {
let pictureData = object["theImg"] as! PFFile
pictureData.getDataInBackgroundWithBlock({ (imageData, error) -> Void in
if error == nil {
if let imageData = UIImage(data: imageData!) where error == nil {
self.theImages.append(imageData)
self.collectionView?.reloadData()
print("The images were added!")
}
} else {
print(error)
}
})
}
} else {
print(error)
}
}
}
最后,在 UICollectionView I am then populating theUICollectionViewCell` 的 dataSource 方法中使用 Parse 中的图像数组。
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = self.collectionView?.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! theCell
//add the images from the array
cell.theImage.image = theImages[indexPath.row]
return cell
}
问题是我收到了这个错误:
2015-09-19 15:49:35.216 SecureSearchv3[17816:700076] [错误]:捕获“NSInvalidArgumentException”,原因为“*** -[_NSPlaceholderData initWithContentsOfFile:options:error:]: nil file argument":
【问题讨论】:
-
你找到解决这个问题的方法了吗?
-
是的,我找到了答案
-
你能把它作为答案发布在下面吗?我也遇到了同样的问题
-
我会,但是我现在在学校
-
我也有。原因是什么?
标签: ios swift parse-platform swift2