I've having trouble getting an image and a row action on a table view cell simultaneously. I can get a few different permutations to work (row action works but image only loads after row action activated, image loads but row action not available) but I cannot get the image to load on page load and to have the row action accessible.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("childrenCell", forIndexPath: indexPath) as! ChildrenTableViewCell
cell.textLabel?.text = childFirstName[indexPath.row]
cell.detailTextLabel?.text = childLastName[indexPath.row]
self.childImage[indexPath.row].getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
if error == nil {
let image = UIImage(data: imageData!)
cell.imageView?.image = image
}
self.tableView.reloadData()
}
return cell
}
The above code is used to populate the cells with data. If I move the self.tableView.reloadData()
around, I get different combinations (but not the one I want). The code for the row action is pretty standard, provides two options for the user.
On a side note, I'd prefer to get the data from Parse in viewDidLoad
query (below), but I can't seem to get that to work. Perhaps the answer is to solve that problem instead of placing the query in the cellForRowAtIndexPath
.
let query = PFQuery(className:"children")
query.whereKey("programID", equalTo: passedProgramID!)
query.findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
if error == nil {
print("Successfully retrieved \(objects!.count) children.")
if let objects = objects {
for object in objects {
self.childFirstName.append(object["childFirstName"] as! String)
self.childLastName.append(object["childLastName"] as! String)
self.childImage.append(object["childImage"] as! PFFile)
}
}
} else {
print("Error: \(error!) \(error!.userInfo)")
}
}
self.tableView.reloadData()