简体   繁体   中英

How to update tableView cell's labels when every time i enter new value in textField?

How to update tableView cell's labels when every time i enter new value in textField?


@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)


        }
    }

This func is button for toolbar in keyboard. When i press "Done" my keyboard close and value is updated.


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


    }

This is my cells.


Every time when I press Done button on keyboard I save a new value to atmosfera var. I want to update my labelResult.label s. How I could do it?

Call reloadData instance method of the tableView any time you want to refresh the whole table

 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 {
}

更新atmosfera后,添加tableView.reloadData() ,这将使用新数据重新加载tableView。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM