无法访问swift中TableViewcell类中的协议函数



我想访问tableviewcell类中协议中的一个函数。但是做不到。有人能帮我解决这个问题吗?

protocol updateLcodeCell: class {
func updateAfterSearchApiCall(searchTextArray: [String]?)
}

class PatientFormTableViewController: UIViewController{
var lcodeDelegate: updateLcodeCell?
func callApi(arr: [String]){
lcodeDelegate?.updateAfterSearchApiCall(searchTextArray: arr)}
}

在我的手机类

class LcodeTableViewCell: UITableViewCell {
weak var lcodeDelegate: updateLcodeCell?

override func awakeFromNib() {
super.awakeFromNib()
self.lcodeDelegate = self
}
}
extension LcodeTableViewCell: updateLcodeCell{
func updateAfterSearchApiCall(searchTextArray: [String]?) {
searcApiResponseDataArray = searchTextArray
}

}

在您的表上ViewindexPath.row方法调用您的委托

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: yourCellId, for: indexPath) as! YourCustomTableCell
cell.lcodeDelegate = self // here call your delegate
return cell
}

最新更新