Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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
Xcode 快速边界不可用_Xcode_Swift_Bounds_Cgpoint - Fatal编程技术网

Xcode 快速边界不可用

Xcode 快速边界不可用,xcode,swift,bounds,cgpoint,Xcode,Swift,Bounds,Cgpoint,当我构建应用程序时,错误指向下面的代码,并表示“边界”不可用。该代码以前工作正常,但现在导致构建失败 let pointInTable: CGPoint = sender.convertPoint(sender.bounds.origin, toView: self.collectionView) let cellIndexPath = self.collectionView?.indexPathForItemAtPoint(pointInTable) println(cellIndexPat

当我构建应用程序时,错误指向下面的代码,并表示“边界”不可用。该代码以前工作正常,但现在导致构建失败

let pointInTable: CGPoint = sender.convertPoint(sender.bounds.origin, toView: self.collectionView)

let cellIndexPath = self.collectionView?.indexPathForItemAtPoint(pointInTable)
println(cellIndexPath)
sender
可能是一个UIButton,但Swift不知道这一点。它只知道你告诉它什么。你必须告诉它,这样斯威夫特就会知道这是一个有着
界限的东西。最简单的方法是施放:

let button = sender as UIButton
let pointInTable: CGPoint = button.convertPoint(button.bounds.origin, toView: self.collectionView)

另外,您确定
self.collectionView
不是可选的吗?在某些版本的Xcode/Swift中,是这样的,您必须将其展开(
self.collectionView!
)。

如何定义
sender
?sender是集合视图单元格中的一个UIButton。