Reputation: 83
I am trying to get images from Parse. I've been working on this code:
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()
}
}
When I run it, it returns only the username and the title of the post, but the place where the image should be is blank. Here is the log:
Thanks in advance
Upvotes: 0
Views: 45
Reputation: 119041
From these details:
(lldb) po cell.PostImage
<UITableViewCellContentView: 0x7fb700ebdc00; frame = (0 0; 320 389); opaque = NO; gestureRecognizers = <NSArray: 0x7fb700ea4c10>; layer = <CALayer: 0x7fb700e71d20>>
(lldb) po cell
<Talent.TableViewCellHome: 0x7fb700ebd3f0; baseClass = UITableViewCell; frame = (0 0; 320 389); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x7fb700e7c7b0>>
We can see that the cell you have dequeued is good, but that the reference to your image view is actually referencing the cell content view.
This is likely a mistake in the outlet connection, you simply need to delete the existing connection and reconnect to the image view.
Upvotes: 1