Downloading PFFile (Image) from Parse append it to array and fill UIImageView with that array (Swift)(从 Parse 下载 PFFile (Image) 将其附加到数组并用该数组 (Swift) 填充 UIImageView)
问题描述
我在解析和 swift 方面遇到问题,希望您能帮助我:)
I have a problem with parse and swift and i hope you can help me :)
我正在从 Parse 下载字符串和 PFfile,并希望将其添加到数组中(这工作正常).
I'm downloading strings and PFfiles from Parse and want to add it to an array (this works fine).
然后我想用字符串数组填充一个标签(也可以正常工作)和一个带有 PFFile 数组的 UIImageView,它也是一个图像.
Then I want to fill a Label with the string array (works fine as well) and an UIImageView with the PFFile array which is also an Image.
但我总是得到一个错误:
But I always get an error:
PFFile 不能转换为UIImage"
PFFile is not convertible to "UIImage
但我不知道如何转换此 PFFile 以便可以将其与 UIImage 视图一起使用.
But I have no clue how I can convert this PFFile so that I can use it with the UIImage View.
var titles = [String] ()
var fragenImages = [PFFile] ()
@IBOutlet weak var fragenIm: UIImageView!
@IBOutlet weak var fragenFeld: UILabel!
override func viewDidAppear(animated: Bool) {
var query = PFQuery(className:"Post")
query.whereKey("user", notEqualTo: PFUser.currentUser().username)
query.limit = 5
query.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
for object in objects {
self.titles.append(object["title"] as String)
self.fragenImages.append(object["imageFile"] as PFFile)
}
self.fragenFeld.text = self.titles[0]
self.fragenIm.image = self.fragenImages[0]
}
else {
println(error)
}
}
}
推荐答案
Daniel,图片不是文件,技术上它们是,但您将它们引用为数据而不是 PFObjects 或 PFFiles.因此,基本上获取文件的数据并像往常一样应用:您只是错过了一个简单的步骤:
Daniel, pictures aren't files, technically they are, but you reference them as Data not PFObjects or PFFiles. So, essentially get the Data of the file and apply as you normally would: You just missed a simple step:
for object in objects {
let userPicture = object["imageFile"] as PFFile
userPicture.getDataInBackgroundWithBlock({ // This is the part your overlooking
(imageData: NSData!, error: NSError!) -> Void in
if (error == nil) {
let image = UIImage(data:imageData)
self.fragenImages.append(image)
}
})
}
这篇关于从 Parse 下载 PFFile (Image) 将其附加到数组并用该数组 (Swift) 填充 UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Parse 下载 PFFile (Image) 将其附加到数组并用该数组 (Swift) 填充 UIImageView
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01