Reputation: 385
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?
Upvotes: 0
Views: 376
Reputation: 19737
Add tableView.reloadData()
after you update the atmosfera
var, that will reload the tableView with the new data.
Upvotes: 2
Reputation: 100503
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 {
}
Upvotes: 2