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

时间:2018-02-08 14:15:34

标签: ios swift uitableview variables uitextfield

每次在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是键盘中工具栏的按钮。当我按下"完成"我的键盘关闭并且值已更新。

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。我怎么能这样做?

2 个答案:

答案 0 :(得分:2)

在您想要刷新整个表格的任何时候调用reloadData的{​​{1}}实例方法

tableView

答案 1 :(得分:2)

在更新core.js:1427 ERROR Error: Uncaught (in promise): Error: StaticInjectorError[HttpClient]: StaticInjectorError[HttpClient]: NullInjectorError: No provider for HttpClient! Error: StaticInjectorError[HttpClient]: StaticInjectorError[HttpClient]: NullInjectorError: No provider for HttpClient! at _NullInjector.get (core.js:993) at resolveToken (core.js:1281) at tryResolveToken (core.js:1223) at StaticInjector.get (core.js:1094) at resolveToken (core.js:1281) at tryResolveToken (core.js:1223) at StaticInjector.get (core.js:1094) at resolveNgModuleDep (core.js:10878) at _createClass (core.js:10915) at _createProviderInstance$1 (core.js:10889) at _NullInjector.get (core.js:993) at resolveToken (core.js:1281) at tryResolveToken (core.js:1223) at StaticInjector.get (core.js:1094) at resolveToken (core.js:1281) at tryResolveToken (core.js:1223) at StaticInjector.get (core.js:1094) at resolveNgModuleDep (core.js:10878) at _createClass (core.js:10915) at _createProviderInstance$1 (core.js:10889) at resolvePromise (zone.js:824) at resolvePromise (zone.js:795) at eval (zone.js:873) at ZoneDelegate.invokeTask (zone.js:425) at Object.onInvokeTask (core.js:4744) at ZoneDelegate.invokeTask (zone.js:424) var之后添加tableView.reloadData(),这将使用新数据重新加载tableView。