【发布时间】:2015-06-25 15:46:24
【问题描述】:
我创建了一个自定义TableViewCell,并且当前在单元格中放置了一个按钮。当按下按钮时,在tableviewcell.swift 文件中,IBAction func 被执行。我无法弄清楚如何确定按下按钮所在的单元格的索引路径。我试图使用以下
@IBAction func employeeAtLunch(sender: AnyObject) {
let indexPath = (self.superview as! UITableView).indexPathForCell(self)
println("indexPath?.row")
}
但我在点击时收到以下错误:
Could not cast value of type 'UITableViewWrapperView' to 'UITableView'
关于如何访问单元格的索引路径的任何帮助?
【问题讨论】:
-
您应该创建一个插座并将其连接到您的 tableView IBOutlet var tableView: UITableView! (您需要从方法中删除覆盖)
标签: ios uitableview swift button