samedi 27 juin 2015

UITableView cell gives different widths. How to solve this?

I have the function heightForRowAtIndexPath to calculate the height of the cell having two textfields of dynamic text

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
    let cell = tableView.dequeueReusableCellWithIdentifier(self.kkCellIdentifier) as! NibTableViewCell
    cell.updateConstraints()
    let width = cell.contentView.frame.width
    //use width to calculate the height
}

I am running this on iPhone 6 simulator.

In portrait:

I get cell width sometimes as 375 (wrong- it is actually tableView's frame width) and sometimes as 320 (Correct one)

In Landscape:

I get cell width sometimes as 320 and sometimes as 659 (Correct one)

Why is it like this? Is this a bug?

How to solve this?

Aucun commentaire:

Enregistrer un commentaire