小编Che*_*dhi的帖子

如何使用 Swift 获取 UITableView Cell 的标签文本?

我想制作简单的 UITabelView。我使用名为 backgroundviewcell 的自定义类注册了它的单元格。我想获取所选单元格的标签。我尝试了很多次,但输出值为零。我也尝试过堆栈溢出的解决方案,但它对我不起作用。这是我的 cellForRowAt indexPath 代码:

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> backgroundViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "soundElementalcell") as! backgroundViewCell


    let imageNames = sections[indexPath.section].images[indexPath.row]

    cell.Labeltittle.text = sections[indexPath.section].items[indexPath.row]
    cell.Labeltittle.textColor = UIColor(hex : 0x90BA27)
    cell.LabelDetail.text = sections[indexPath.section].detail[indexPath.row]
    //cell.detailTextLabel?.textColor = UIColor.red
    //cell.isHighlighted = false

    cell.backgroundColor = UIColor.clear
    cell.iconview.image = UIImage(named: imageNames)

     return cell
}
Run Code Online (Sandbox Code Playgroud)

这是我的 didSelectRowAt indexPath 代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)  {


    let indexPath = tableView.indexPathForSelectedRow!
    let currentCell = tableView.cellForRow(at: indexPath)!

    celltext = …
Run Code Online (Sandbox Code Playgroud)

arrays uitableview swift

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

arrays ×1

swift ×1

uitableview ×1