I have a UITableView
that's top edge is attached to the bottom of a UIButton
. The UITableView
's edges are attached to the edges of the screen.
The UITableView
has a height constraint that is initially set to 0
, and then when pressing the UIButton
I animate the height constraint constant to the desired size, effectively expanding the UITableView
out below the UIButton
. Tapping the UIButton
again animates the constant back to 0
collapsing and hiding the UITableView
again.
The issue I'm having is that on first load/expansion of the UITableView
, as the cells appear, they do not seem to be the correct width - the right hand end (including its content) seem to expand out slightly. If I collapse the UITableView
and then re-expand it again, the bug doesn't occur so it only seems to happen on first load of the cells.
I have tried this with both default Value1
type cells, and also with custom cells from Nibs and the problem occurs with both.
I have also tried calling cell.layoutIfNeeded()
and cell.layoutSubviews()
before return cell
in cellForRowAtIndexPath()
but neither have any effect.
The problem only occurs on iPhone 6 and later, presumably because the screen got slightly wider from this device. On iPhone 5S and older, the cells load fine first time. It almost seems as if the cells initially load at iPhone 5S and lower width, and then expand outwards on the larger devices.
The problem seems to be something to do with changing the UITableView
's height constraint constant value, but I'm not sure why.
Thanks in advance for any help.
EDIT
Added cellForRowAtIndexPath()
code:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell?
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")
}
cell!.textLabel?.font = UIFont(name: "HelveticaNeue", size: 14)
cell!.textLabel?.textColor = UIColor.lightGrayColor()
cell!.textLabel?.text = self.someArray[indexPath.row]
return cell!
}