swift3将int转换为indexPath

swift3将int转换为indexPath,swift3,Swift3,是否有机会将整数强制转换为索引XPath 因为我需要在按下按钮时从单元格中取出文本。或者我可以使用字符串作为按钮的发送者吗 cell.uncheckbox.tag = indexPath.row as! IndexPath cell.uncheckbox.addTarget(self, action: #selector(ViewController.btnClicked), for: UIControlEvents.touchUpInside) func btnClicked(sen

是否有机会将整数强制转换为索引XPath

因为我需要在按下按钮时从单元格中取出文本。或者我可以使用字符串作为按钮的发送者吗

cell.uncheckbox.tag = indexPath.row as! IndexPath

cell.uncheckbox.addTarget(self, action: #selector(ViewController.btnClicked), for: UIControlEvents.touchUpInside)




func btnClicked(sender: UIButton)
{

    let row = sender.tag
    let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: row) as! TableViewCell;

    print("cellentext \(cell.textLabel?.text)")
}

谢谢你的帮助

当前要做的是为按钮所在行获取一个新单元格。这可能不是你需要的

let row = sender.tag
let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: row) as! TableViewCell;
您想要的是使用
标记作为
indepath
中的行参数。假设只有一个部分,您可以这样构造自己的IndexPath:

let indexPath = IndexPath(row: tag, section: 0)
然后使用
UITableView
cellForRow(at:IndexPath)
方法获取当前单元格

let cell = tableView.cellForRow(at: indexPath)

希望有帮助。

请检查代码片段或输出的缩进。不知怎么的,它看起来不对劲。非常感谢。