我陷入了构建我的应用程序的问题。基本上我有一个tableview显示自定义单元格中的数据。现在这个小区被分成两个图像;一个在左边,一个在右边。找出点击单元格的坐标
单击单元格时;调用didSelectRowAtIndexPath
方法,但是我想找出单元格的哪个部分被点击;无论是正确的图像还是左侧的图像。
做到这一点的一种方法是压倒我自定义单元类的touchesbegan
事件;我可以通过这种方式获得触摸的坐标,并手动检查是选择了左侧图像还是右侧图像;然而这导致事件没有被解雇。
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
let location = touch.locationInView(self)
var xcoord = location.x
touchPosition = xcoord
}
这个代码是什么我想在我的自定义单元格级使用,但我现在不知道怎么火didSelectRowAtIndexPath
事件中,该小区在表格中。我也没有提及那张桌子。
这里touchPosition是一个全局变量,我试图设置它,以便我可以在我的didSelectrowAtIndexPath
方法中访问它,但它不会被解雇。
插座连接到您的tableView并删除重写 –
您可以使用VAR selectedCell = tableView.cellForRowAtIndexPath(indexPath)作为的UITableViewCell获得的细胞在didselect方法! – Amit89
你必须调用'super'。 –