gpt4 book ai didi

ios - 每次在 textField 中输入新值时如何更新 tableView 单元格的标签?

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

每次在 textField 中输入新值时,如何更新 tableView 单元格的标签?


@objc func doneClicked() {
view.endEditing(true)

//MARK: - ФОРМАТТЕР
let formatter = NumberFormatter()
formatter.locale = Locale.current
formatter.numberStyle = .decimal
formatter.minimumFractionDigits = 3
formatter.maximumFractionDigits = 6

if let text = textField.text, let number = formatter.number(from: text) {

atmosfera = number.doubleValue

print(atmosfera)


}
}

此功能是键盘工具栏的按钮。当我按下“完成”时,我的键盘关闭并且值被更新。


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


let cell1 = tableView.dequeueReusableCell(withIdentifier: "resultCell") as! resultTableViewCell


cell1.nameResult.text = converters[indexPath.row]
cell1.labelResult.text = String(convertatmo[indexPath.row] * atmosfera)


return cell1


}

这是我的细胞。


每次当我按下键盘上的完成按钮时,我都会将一个新值保存到 atmosfera var。我想更新我的 labelResult.label。我该怎么做?

最佳答案

任何时候你想刷新整个表格时调用tableViewreloadData实例方法

 if let text = textField.text, let number = formatter.number(from: text) {

atmosfera = number.doubleValue

print(atmosfera)

self.tableView.reloadData()

}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
}

关于ios - 每次在 textField 中输入新值时如何更新 tableView 单元格的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48687606/

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