0

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()
Craig.Pearce
  • 746
  • 7
  • 25
  • There is no need to call `reloadData` in `cellForRowAtIndexPath` – Paulw11 Dec 12 '15 at 03:51
  • If I remove it, the images only get loaded when I either tap the cell or when I swipe to activate the row. Otherwise it stays hidden. If I leave it in as above, the image loads when the view loads, but the row actions are not accessible (do not appear when I swipe). – Craig.Pearce Dec 12 '15 at 04:19
  • Where do you create the row actions for your cell? Are you cell layout constraints set correctly? Are you getting any auto layout warnings? – Paulw11 Dec 12 '15 at 04:22
  • Row actions are created further down the swift file using `editActionsForRowAtIndexPath`. No autolayout errors that are related. Cell `Style` is set to `Subtitle` - could this be the issue? Should it be `Custom`? `Disclosure Indicator` is on. `Table View` `Content` is set to `Dynamic Properties`. – Craig.Pearce Dec 12 '15 at 20:59

0 Answers0