有问题的代码是
if let productImageFile = productData!["productImage"] as? PFFile {
productImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
let image = UIImage(data:imageData)
self.productImageView.image = image
}
}
}
}
我没有任何错误,但图像只是不想从Parse加载。其他所有东西都加载并显示得很好,但无论我等待多久,图像都不会加载。如果我将UIImageView更改为PFImageView,并在接口生成器中将UIImageView的类更改为PFImageView,则会给出3个链接器错误:
架构x86_64的未定义符号:“_ kPFErrorInvalidImageData”,引用自:___ 32- [PFImageView loadInBackground:] _ block_invoke30在ParseUI中(PFImageView.o) “_kPFErrorUnsavedFile”,引自: - ParseUI中的[PFImageView loadInBackground:](PFImageView.o)
ld:找不到架构x86_64的符号
clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
感谢任何帮助。完整的ViewController代码如下。
import UIKit
import Parse
import Bolts
import ParseUI
class ViewController: UIViewController {
@IBOutlet weak var dayOfTheWeekLabel: UILabel!
@IBOutlet weak var productTitleLabel: UILabel!
@IBOutlet weak var productImageView: UIImageView!
@IBOutlet weak var productPriceLabel: UILabel!
@IBOutlet weak var productDescriptionLabel: UILabel!
@IBOutlet weak var buyButton: UIButton!
@IBOutlet weak var refreshButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
//Create new PFQuery to retrieve info from Parse
var query: PFQuery = PFQuery(className: "MyProduct")
//function to get the data
func getProductData (){
//call function to get the data from parse by specifyng an objectId
query.getObjectInBackgroundWithId("XXXXXXXXXX") {
(productData:PFObject?, error:NSError?) -> Void in
if error == nil && productData != nil {
//Extract values from the productData PFObject and store them in constants
let dayOfTheWeek = productData!.objectForKey("day") as! String
let productTitle = productData!.objectForKey("productTitle") as! String
//-----start image loading
if let productImageFile = productData!["productImage"] as? PFFile {
productImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
let image = UIImage(data:imageData)
self.productImageView.image = image
}
}
}
}
//-----end image loading
let productPrice = productData!.objectForKey("productPrice") as! String
let productDescription = productData!.objectForKey("productDescription") as! String
//take the saved constants and assign their values to the labels and UIImage on screen
self.productTitleLabel.text = productTitle
self.dayOfTheWeekLabel.text = dayOfTheWeek
//self.productImageView.image! = productImageFile
self.productPriceLabel.text = productPrice
self.productDescriptionLabel.text = productDescription
} else if error != nil {
println("Could not load data from Parse")
}
}
}
//Print out a message if we're able to get to this part of the program.
println("Reached getProductData function. Now asking for data.")
getProductData()
}