gpt4 book ai didi

ios - 如何在 UITableView 中引用 UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 09:30:29 24 4
gpt4 key购买 nike

表格 View 和单元格已创建并填充了标签和 slider 。当值更改时,我在 slider 上有一个 IBAction。

如何将该值返回到单元格中的标签中?

我在 TableView 中链接了一个 IBOutlet。

@IBAction func slideChange(_ sender: UISlider) {

let currentValue = sender.value // gets slider's value
let row = sender.tag // gets slider's row in table

myTableView.cell.myLabel.text = sender.value // Here i need to show updated value


print("Slider in row \(row) has a value of \(currentValue)") // works
}

最佳答案

试试这个:

@IBAction func slideChange(_ sender: UISlider){
let cell: UITableViewCell? = (sender.superview?.superview as? UITableViewCell) // track cell using your view hierarchy and this your cell
cell.myLabel.text = sender.value
}

  let rootViewPoint: CGPoint? = sender.superview?.convert(sender.center, to: tblView)
var indexPath: IndexPath? = tblView?.indexPathForRow(at: rootViewPoint!)
let cell: UITableViewCell? = tblView?.cellForRow(at: indexPath!)

关于ios - 如何在 UITableView 中引用 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44155278/

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