2

I have a UIViewController with table view which takes the data from Parse and it works well with auto sizing. While reading the documentation I saw that there is a controller named PFQueryTableViewController which comes whit pagination, pull to refresh and other cool features. But now the auto sizing doesn't work and every cell covers the next. Here's my code:

import UIKit

class WallParse: PFQueryTableViewController {


    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        self.parseClassName = "Post"
        self.pullToRefreshEnabled = true
        self.paginationEnabled = true
        self.objectsPerPage = 3

    }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.estimatedRowHeight = 400
        self.tableView.rowHeight = UITableViewAutomaticDimension

    }

    override init!(style: UITableViewStyle, className: String!) {
        super.init(style: style, className: className)
    }

    override func queryForTable() -> PFQuery {

        var query = PFQuery (className: self.parseClassName)

        // If no objects are loaded in memory, we look to the cache first to fill the table
        // and then subsequently do a query against the network.

        if (self.objects.count == 0) {

            query.cachePolicy = kPFCachePolicyCacheThenNetwork;

        }

        query.orderByDescending("createdAt")


        return query
    }

    override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {

        let cellIdentifier = "cell"

        var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as WallCell

        // Configure the cell to show todo item with a priority at the bottom
        cell.commentLabel.text = object["text"] as? String

        return cell;
    }


    override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
}
charbinary
  • 1,875
  • 4
  • 17
  • 25
  • This answer (http://stackoverflow.com/a/25088061/394484) seems to indicate that you have to override the internal auto-resizing mask or else the "old" system kicks in. Since you're getting the cells "for free" from the Parse `PFQueryTableViewController`, have you made sure they play nicely with this new feature? – mbm29414 Feb 04 '15 at 13:19
  • After your comment I put self.setTranslatesAutoresizingMaskIntoConstraints(false) in the awakeFromNib of the PFTableViewCell but the result is the same. – charbinary Feb 04 '15 at 13:40
  • How did you do that? In my (default) implementation of Parse/ParseUI, I only have the headers in my project. – mbm29414 Feb 04 '15 at 13:45
  • I also have this message in the output: "Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view" which I think is because prior to the iOS 8 it was necessary to suply height for the cell. It doesn't appear when I don't use PFQueryTableViewController. – charbinary Feb 04 '15 at 13:46
  • What do you mean by "How did you do that?"? I have custom PFTableViewCell and put self.setTranslatesAutoresizingMaskIntoConstraints(false) in the awakeFromNib method – charbinary Feb 04 '15 at 13:48
  • You mean you **subclassed** `PFTableViewCell`? Or did you make your own? And are you designing these cells in a Storyboard/XIB or creating them in code? If creating in code, `awakeFromNib` is never called. Instead, you should handle `initWithFrame:`. – mbm29414 Feb 04 '15 at 13:53
  • I made a cell in a Stroryboard and subclassed PFTableViewCell. Sorry, I didn't make it clear. – charbinary Feb 04 '15 at 13:55
  • Try (in `awakeFromNib`): `self.contentView.setTranslates...(false)` – mbm29414 Feb 04 '15 at 14:05
  • It's the same... Maybe parse will fix that in the future but for now I will go back with the UIViewController and I will implement paging and the other things by myself. Thank you very much for your time and help! – charbinary Feb 04 '15 at 14:13
  • @bekiJeriDon Were you able to get the autoresizing cells to work in your PFQueryTableViewController or have you continued using UIViewController? – dnadri Jan 20 '16 at 05:41

0 Answers0