如何在不创建 *Cell.swift-file 的情况下访问 UITableViewCell 对象

How to access UITableViewCell object without creating *Cell.swift-file

我有带动态单元格的 tableView。

tableViewCell 我有 2 labels1 button

在函数 cellForRowAtIndexPath 中,我通过这样的代码字符串向它的按钮添加操作:

btn?.addTarget(self, action: "downloadButtonClicked:", forControlEvents: .TouchUpInside)

我当然有这个功能

func downloadButtonClicked(sender: AnyObject){

}

在这个函数中,我可以通过

访问它的 Cell 按钮
(sender as UIButton)?.hidden = true //for example

但是我如何从这个函数访问这些标签 - downloadButtonClicked?

它们有特定的标签值,但我不知道如何访问它们。很多实现“viewWithTag”的变体都不让我满意

我需要变体而不需要为此单元格创建特定文件“MyTableViewCell.swift”

像这样先找到按钮索引:

var btnPos: CGPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
var indexPath: NSIndexPath = self.tableView.indexPathForRowAtPoint(btnPos)!

然后使用我们刚刚得到的indexPath创建cell

 cell  = tableView.cellForRowAtIndexPath(indexPath) as! YourTableViewCellClass

然后您可以使用

访问您的标签
 cell.yourLabel.text = "anything"