从解析中检索文本很简单,但是当我尝试使用图像时,我似乎无法匹配这两种类型以使其以任何方式工作。代码如下:
@IBOutlet weak var realProfilePictureBackground: UIImageView!
@IBOutlet weak var realProfilePicture: UIImageView!
@IBOutlet weak var realNameLabel: UILabel!
@IBOutlet weak var realUsernameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let userFirstName = (PFUser.currentUser()?.objectForKey("firstName") as? String)!
let userlastName = (PFUser.currentUser()?.objectForKey("firstName") as? String)!
let userUsername = (PFUser.currentUser()?.objectForKey("username") as? String)!
let profilePicture = (PFUser.currentUser()?.objectForKey("profilePicture") as? PFFile)!
realNameLabel.text = userFirstName + " " + userlastName
realUsernameLabel.text = userUsername
realProfilePictureBackground = profilePicture
}
字符串工作正常,但图像出错:
我认为Cannot assign a value of type 'PFFile to a value of type 'UIImageView!'
是有道理的,但我该怎么做?
答案 0 :(得分:0)
使用:
if let userPicture = PFUser.currentUser()?.objectForKey("profilePicture")! as! PFFile {
userPicture.getDataInBackgroundWithBlock({
(imageData: NSData!, error NSError!) -> Void in
if (error == nil) {
let image = UIImage(data:imageData)
//self.ImageArray.append(image)
dispatch_async(dispatch_get_main_queue()){() -> Void in
realProfilePictureBackground.image = image
}
}
})
}