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
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
