how to clear the text from the textfield after entering one data from other cell

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how to clear the text from the textfield after entering one data from other cell



Once i 15 cells in the tableview.In the tableviewcell i have textfield, i firstly enter the data in the textfield of the 1st cell.Then clicked on enter.But while scrolling the entered text is displaying in the other textfield.How to solve it?



This is my delegate method of the textfield..


func textFieldDidBeginEditing(_ textField: UITextField)
texttype.text = ""



func textFieldShouldClear(_ textField: UITextField) -> Bool

return true


func textFieldDidEndEditing(_ textField: UITextField)
self.TextAction(texttype)



func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool


return true;




func textFieldShouldEndEditing(_ textField: UITextField) -> Bool

return true;






func textFieldShouldReturn(_ textField: UITextField) -> Bool
print(texttype.text)
texttype.resignFirstResponder()
// self.TextAction(texttype)

return true





Are this textFields are inside in tableview Cell ?
– Ajharul Islam
12 mins ago





yes...i have one textfield in the tableviewcell,
– meggie
10 mins ago





it happens because fo tableview reuse cells .
– Ajharul Islam
10 mins ago




1 Answer
1



Declare a array which can store table View text .


var arrString = ["","",""] // each empty string for each text field



in you tableview data source set a tag for each textField . and set value from array


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
cell.textField.tag = indexPath.row
cell.textField.text = arrString[indexPath.row]
return cell




in textFieldShouldReturn


func textFieldShouldReturn(_ textField: UITextField) -> Bool

texttype.resignFirstResponder()
let index = textField.tag
arrString[indexPath.row] = textField.text
return true






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard