【发布时间】:2016-11-17 18:37:59
【问题描述】:
在我的viewController 中,我有这个带有自定义单元格的tableView。
根据我的 viewController 的 坐标系,在我的 cellForRow:atIndexPath: 方法中,我想访问显示在特定位置的 UIButton 的位置 (rect)细胞。
这就是我认为它会起作用的方式:
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cellId") as? MyCell
if cell != nil {
cell = MyCell(style: .Default, reuseIdentifier: "cellId")
}
let convertedFrame = view.convertRect(cell!.myButton.Frame, fromView: cell)
return cell!
}
它只是给我按钮在它自己的坐标系中的当前框架(0.0, 0.0, 44.0, 44.0)
关于正确使用该方法的任何线索?
【问题讨论】:
-
您为什么要在
cellForRowAtIndexPath中这样做?该单元格甚至还没有添加到表格中。 -
嗯。那讲得通。这可能是一个不好的地方。
-
这不仅有意义,而且还成功了。非常感谢。
标签: ios swift uiview coordinates frame