【发布时间】:2015-05-14 23:07:56
【问题描述】:
我在一个仅限 iOS 8 的应用程序中使用尺寸类,并且我在 UITableViewCell 内有一个具有灵活宽度的视图。其自动布局约束定义如下:
如您所见,其宽度因设备宽度/方向而异。
当我在 cellForRowAtIndexPath 中打印它的框架时,我看到 (180.0, 10.0, 400.0, 60.0) 显示 400 宽度。但是当我在模拟器中测量视图时,它只有 175 宽,而我的视图内容被截断(我在里面画了一些东西)这一事实进一步证明了这一点。
我如何知道UITableViewCell 的约束和子视图何时完全完成渲染,以便我可以在视图中重绘内容?
更新
在cellForRowAtIndexPath 中,我正在执行以下操作来获取单元格:
let cell = tableView.dequeueReusableCellWithIdentifier("TimeTypeCell", forIndexPath: indexPath) as! TimeTypeCell
let customField = customFields[indexPath.row]
cell.fieldNameLabel.text = customField["name"] as? String
cell.fieldValueLabel.text = customField["total"] as? String
cell.graphData = customField["totalGraph"] as! [Double]
cell.fieldGraph.dataSource = cell.self
cell.fieldGraph.delegate = cell.self
cell.fieldGraph.reloadData() //This is where the redrawing happens
【问题讨论】:
-
试试 viewDidLayoutSubviews
-
据我了解,
viewDidLayoutSubviews是UITableViewController的一种方法。UITableViewCell有没有等价的东西?
标签: ios uitableview swift autolayout