Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Can';无法使convertRect:从视图到工作_Ios_Swift_Uiview_Coordinates_Frame - Fatal编程技术网

Ios Can';无法使convertRect:从视图到工作

Ios Can';无法使convertRect:从视图到工作,ios,swift,uiview,coordinates,frame,Ios,Swift,Uiview,Coordinates,Frame,在我的viewController中,我有一个带有自定义单元格的tableView。 在我的cellForRow:atIndexPath:方法中,我想根据我的视图控制器的坐标系访问特定单元格内显示的UIButton的位置(rect)。 这就是我认为它会起作用的方式: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableVie

在我的
viewController
中,我有一个带有自定义单元格的
tableView
。 在我的
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)


关于该方法的正确用法有什么线索吗?

只需在单元格实际放入视图层次结构之前调用它即可。多亏了rmaddy指出了它。

只需在单元格实际放置到视图层次结构之前调用它即可。感谢rmaddy的指出。

改变

let convertedFrame = view.convertRect(cell!.myButton.Frame, fromView: cell)

改变


为什么要在
单元格中执行此操作?单元格甚至还没有添加到表中。这是有道理的。这可能是一个不好的地方。它不仅有意义,而且也起到了作用。非常感谢。为什么要在
CellForRowatineXpath
中执行此操作?单元格甚至还没有添加到表中。这是有道理的。这可能是一个不好的地方。它不仅有意义,而且也起到了作用。非常感谢你。
let convertedFrame = view.convert(cell!.myButton.Frame, fromView: cell)