Here is how I tried to achieve my needs:
func textFieldDidChangeSelection(_ textField: UITextField) {
let tapLocation = textField.convert(textField.bounds.origin, to: tableView)
guard let pickedCurrencyIndexPath = tableView.indexPathForRow(at: tapLocation) else { return }
//Append only if array don't have the IndexPath already
if !indexPathsArray.contains(where: {$0 == pickedCurrencyIndexPath}) {
indexPathsArray.append(pickedCurrencyIndexPath)
}
//I need to compare only 2 last IndexPaths, so delete the most old at position 0 in array
if indexPathsArray.count > 2 {
indexPathsArray.remove(at: 0)
}
for indexPath in indexPathsArray {
if indexPath.last != indexPath.first {
//user clicked on a new textfield,clear all so he can type a new number
numberFromTextField = 0
textField.placeholder = "0"
textField.text = ""
}
}
print(indexPathsArray)
}
With this code I almost achieved what I need except when I click on a new textField I can't type anything...
GIF: cln.sh/sGNlBE
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: