0
我正在嘗試從Parse中獲取圖像。我一直對這個代碼:從Parse中檢索圖像
import UIKit
import Parse
import ParseUI
class ViewControllerHome: UIViewController, UITableViewDelegate, UITableViewDataSource {
var imagesFiles = [PFFile]()
var imageUser = [String]()
var imageTitle = [String]()
@IBOutlet weak var MessageTable: UITableView!
let color = UIColor(red: 0.0/255.0, green: 105.0/255.0, blue: 92.0/255.0, alpha: 1)
let colore = UIColor.whiteColor()
let coloree = UIColor(red: 33.0/255.0, green: 33.0/255.0, blue: 33.0/255.0, alpha: 1)
override func viewDidLoad() {
let query = PFQuery(className: "Messages")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (posts: [PFObject]?, error: NSError?) -> Void in
if error == nil {
for post in posts! {
self.imagesFiles.append(post["Post"] as! PFFile)
self.imageUser.append(post["Name"] as! String)
self.imageTitle.append(post["Title"] as! String)
}
self.MessageTable.reloadData()
}else{
print(error)
}
}
super.viewDidLoad()
self.navigationController?.navigationBar.barTintColor = color
self.navigationController?.navigationBar.tintColor = colore
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: colore]
UITabBar.appearance().barTintColor = coloree
UITabBar.appearance().tintColor = colore
UITabBar.appearance().translucent = false
self.MessageTable.delegate = self
self.MessageTable.dataSource = self
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = MessageTable.dequeueReusableCellWithIdentifier("cell")! as! TableViewCellHome
//text
cell.UsernameLabel.text = imageUser[indexPath.row]
cell.Title.text = imageTitle [indexPath.row]
//image
imagesFiles[indexPath.row].getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
if imageData != nil {
let image = UIImage(data: imageData!)
cell.PostImage.image = image
}else{
print(error)
}
}
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return imagesFiles.count
}
@IBAction func refresh(sender: AnyObject) {
MessageTable.reloadData()
}
}
當我運行它,它返回只有用戶名和文章的標題,但在圖像應該待的地方是空白。下面是日誌:
在此先感謝
你調試了什麼postimage連接到? – Wain
@很抱歉,但我該怎麼辦? –
在設置圖像的位置放置一個斷點,例外說明,當你這樣做的時候,它實際上並不是一個圖像視圖... – Wain