How fix tableView scroll problem when keyboard is open?

I'm trying reload all cells when variable was changed.
Problem was appearing only in bottom cell of tableView. TableView scrolling unexpected way (it was scrolling top and bottom)

Code Block
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath) as? ConverterTableViewCell,
let code = cell.currency.text
else { return }
cell.priceText.text = "0"
convertCurrencyForCode(with: code)
cell.priceText.delegate = self
cell.priceText.addTarget(self, action: #selector(textChanged(_:)), for: .editingChanged)
cell.priceText.addTarget(self, action: #selector(onTextFieldTap), for: .touchDown)
writedNumber = 0
tableView.reloadData()
cell.priceText.becomeFirstResponder()
selected = indexPath.row
}
@IBAction func textChanged(_ textField: UITextField) {
if let text = textField.text {
writedNumber = Double(textField.text!)
tableView.reloadData()
}
}

Why do you reload once selected. That removes the selection, hence may cause a problem.

In addition, you add target in didSelectRowAt.
That should be done instead in cellForRow at
Because every time when i clicking to cell, i am calling apiCall and getting new information. And Each of cell's has a textfield, when i writing on textfield all cell's some values changing (textfieldValue * apiCall_Value)

OK, so you need to reload the table.

But this code
Code Block
cell.priceText.delegate = self
cell.priceText.addTarget(self, action: #selector(textChanged(_:)), for: .editingChanged)
cell.priceText.addTarget(self, action: #selector(onTextFieldTap), for: .touchDown)

should be in cellForRow.

Could you also try:
  • to comment out reloadData()

to see if the problem disappear.
  • And also try to add a reselect after reloadData()

Code Block
tableView.reloadData()
tableView.electRow(at: index, animated: true, scrollPosition: UITableViewScrollPosition.none) // May test other UITableViewScrollPosition

How fix tableView scroll problem when keyboard is open?
 
 
Q