我有一个带有表视图的UIViewController,它从Parse获取数据,并且它适用于自动调整大小。在阅读文档的过程中,我看到有一个名为PFQueryTableViewController的控制器,它具有分页,拉动刷新和其他很酷的功能。但是现在自动调整大小并不起作用,每个单元格都覆盖下一个。这是我的代码:
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
}
}