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。