出于某种原因,在 xcode 6 中使用尺寸等级时,我的单元格中的 subview 宽度不正确。我有一个 UIImageView
,带有用于调整大小的自动布局(常量:顶部、左/右、底部为 10)。
当从 tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!)
调用以下内容时:
println("w: \(cell.mapSnapshotImageView.bounds.size.width) h: \(cell.mapSnapshotImageView.bounds.size.height)")
我总是得到:
w: 580.0 h: 80.0
尽管它应该是w: 300.0 h: 80.0
,基于我在 iPhone 5S 上的 320x100 电池。
一切都显示正确,但我想使用 subview 的宽度来计算其他 subview 。关于为什么会发生这种情况的任何想法?错误报告或按设计工作?
编辑:
此问题仅适用于最初加载的单元格。当细胞被重复使用时,问题就不会出现了。 println
重用单元格的输出:
w: 300.0 h: 80.0
最佳答案
在访问帧之前调用 willDisplayCell:forRowAtIndexPath
中的 cell.layoutIfNeeded()
。这样就可以了。
关于ios - UITableViewCell subview 在使用大小类时报告不正确的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25559732/