我正在尝试获取在视图控制器中使用此函数的单元格的indexpath
。
func getIndex(cell : TableViewCell1) -> IndexPath
{
let x = cell.cellTextField.convert(CGPoint.zero, to: self.tableView)
let indexPath = self.tableView.indexPathForRow(at: x)
return indexPath!
}
它工作得很好,但当我尝试将此函数返回的值用于我的IBAction方法时:
@IBAction func tapButton(_ sender: UIButton) {
let indexPath1 = getIndex(cell: TableViewCell1)
}
我收到这个错误
无法将类型为"TableViewCell1.type"的值转换为所需的参数类型"TableViewCell1"。
需要相关帮助。如果这是一个非常基本的问题,请原谅我,因为我正在迅速地学习。
错误消息说该方法获取的对象是TableViewCell1类型,但您给出的是类型定义。
如果方法tapButton在TableViewCell1的子类中,则
class TableViewCell1: UITableViewCell {
@IBAction func tapButton(_ sender: UIButton) {
let indexPath1 = getIndex(cell: self)
}
}