我有TableView,它有2个标签的单元格。我想在加载操作期间为两个标签设置值。但是,我无法访问这两个标签。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let fr = fractionList[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "FrictionCell", for: indexPath) as! SwipeTableViewCell
cell.delegate = self
cell.textLabel?.text = fr.fraction
//cell.textLabel?.text = fr.decimal
cell.backgroundColor = UIColor(hexString: fr.color ?? "#FFFFFF")
return cell
}
你不能有两个同名的标签,所以你可以重命名标签的出口,使其在你的细胞中有两个出口SwipeTableViewCell
:
@IBOutlet weak var lblFractionOutlet: UILabel!
@IBOutlet weak var lblDecimalOutlet: UILabel!
然后您可以在函数cellForRowAt
:中访问它们
cell.lblFractionOutlet.text = fr.fraction
cell.lblDecimalOutlet.text = fr.decimal
我希望它能对你起作用。。。