gpt4 book ai didi

ios - Collection View 中的多个 TableView

转载 作者:行者123 更新时间:2023-11-28 10:40:04 25 4
gpt4 key购买 nike

我正在处理 Collection-view 内的多个 Tableviews。我跟着this文章。但是在 cellForRowAt indexPath 方法中我遇到了以下错误。

Value of type 'UITableViewCell' has no member 'lblLab'
Value of type 'UITableViewCell' has no member 'lblLab'
Value of type 'UITableViewCell' has no member 'lblMedicine'

我已经为所有三个表格 View 单元格创建了单独的类,其中已经提到了所有三个标签。

下面是我在 Collection View 单元类中编写的相同代码。

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell : UITableViewCell;
if tableView == tableLAB {
cell = tableView.dequeueReusableCell(withIdentifier: "labCell", for: indexPath) as! LabTableCell;
cell.lblLab!.text = arr1[indexPath.row];
} else if tableView == tableDIAGNOSIS {
cell = tableView.dequeueReusableCell(withIdentifier: "diagnosisCell", for: indexPath) as! DiagnosisTableCell;
cell.lblDiagnosis!.text = arr1[indexPath.row];
} else if tableView == tableMEDICINE {
cell = tableView.dequeueReusableCell(withIdentifier: "medicineCell", for: indexPath) as! MedicineTableCell;
cell.lblMedicine!.text = arr1[indexPath.row];
}

return cell;
}

你能告诉我我做错了什么吗?提前致谢。

最佳答案

问题是您试图强制将通过父类初始化的对象强制转换为子类,这是不可能的,您可以做的是确保您对所有情况都有条件运算符,即

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

if(tableview == a){
//This is a conditional statement
}
else if(tableview == b){
//This is a conditional statement
}
else{
//This is a conditional statement
}

//no need to return anything here as your conditional operators are handling all return //cases
}

并且在每个条件语句中,声明并初始化您的唯一单元格类型并将其返回,例如。

let cell : CellType = tableView.dequeueReusableCell(withIdentifier: "CellType", for: indexPath) as! CellType;
return cell;

关于ios - Collection View 中的多个 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51057630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com