I have a UITableView inside of a UIView that I perform the function insertRowsAtIndexPaths
on. More content appears, but the UITableView height remains the same. I've read through hundreds of SO posts for days now, and can't seem to understand why this isn't updating.
var tableView = UITableView()
tableView.frame = CGRectMake(0, 0, self.view.frame.width, view.frame.height)
tableView.estimatedRowHeight = 40
tableView.scrollEnabled = true
tableView.userInteractionEnabled = true
tableView.rowHeight = UITableViewAutomaticDimension
tableView.delegate = self
tableView.dataSource = self
Then I if I click a cell..
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let (parent, isParentCell, actualPosition) = self.findParent(indexPath.row)
self.tableView.beginUpdates()
self.updateCells(parent, index: indexPath.row)
self.tableView.endUpdates()
var frame : CGRect = self.tableView.frame
print(frame.size) // Returns -> (375.0, 667.0)
frame.size = self.tableView.contentSize
print(frame.size) // Return -> (375.0, 1151.0)
self.tableView.frame = frame
}
But the height of the UITableView remains 667.0 as seen here :
.. even though you can clearly see the contentSize now transcends the bounds.
What could I possibly be missing here?
Update
-- Here is how I draw cellForRowAtIndexPath
..
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell : UITableViewCell!
let (parent, isParentCell, actualPosition) = self.findParent(indexPath.row)
if !isParentCell {
cell = tableView.dequeueReusableCellWithIdentifier(childCellIdentifier, forIndexPath: indexPath)
cell.textLabel!.text = self.dataSource[parent].childs[indexPath.row - actualPosition - 1]
cell.textLabel!.textColor = UIColor(red: 35/255.0, green: 31/255.0, blue: 32/255.0, alpha: 1.0)
cell.textLabel!.font = UIFont(name: "STHeitiTC-Light", size: 16)
cell.textLabel!.layer.borderColor = UIColor.purpleColor().CGColor
cell.textLabel!.layer.borderWidth = 1.0
}
else {
cell = tableView.dequeueReusableCellWithIdentifier(parentCellIdentifier, forIndexPath: indexPath)
cell.textLabel!.text = self.dataSource[parent].title
cell.textLabel!.textColor = UIColor(red: 66/255.0, green: 116/255.0, blue: 185/255.0, alpha: 1.0)
cell.textLabel!.font = UIFont(name: "STHeitiTC-Light", size: 20)
}
cell.textLabel!.frame = CGRectMake(0,0,self.view.frame.width, CGFloat.max)
cell.selectionStyle = .None
cell.textLabel!.translatesAutoresizingMaskIntoConstraints = false
cell.textLabel!.numberOfLines = 0
cell.textLabel!.sizeToFit()
cell.textLabel!
return cell
}
A visual of the problem..