0

I have a tableview with customcells with textfields in it. I am facing a peculiar problem now:

  1. When I tap on first row textfield, -beginEditing gets called.
  2. Now I change the value and tap on second row textfield. So, the -didEndEditing of first row gets called. In this didEnd, I have some parsing methods which are called in some other class. But they are not executed now. Right after the didEnd, -beginEditing of second row text is called. After that the parsing happens. Till now, it is fine.
  3. When the parsing is finished, objects from parsing is set in other classes,the flow should stop here, but I don't know from where and why, The -didEndEditing for the second row gets called ! Also, though any resignfirstresponder is not written anywhere, the keyboard gets dismissed !

Any clue why is this happening and how to solve it ?

utsabiem
  • 920
  • 4
  • 10
  • 21

1 Answers1

0

This is the way Apple designed the system - all developers have to deal with it (right or wrong). The key is that you are given the "textField" property so you know WHICH one of the textFields is sending the delegate messages.

The solution is to use one or more mutable dictionaries (or some data structure) to keep state for each individual textField. You can have a primary dictionary that uses the textField object as the key, then for each textField a dictionary that has the current state, and any other info you want to retain about it.

You can probably hack a less elegant but easier to code solution to. In any case, there is overlap on these messages and there is not way to avoid it.

EDIT: use the tag as the key, or create a non-retained NSValue pointer object, but don't use the text field itself.

David H
  • 40,852
  • 12
  • 92
  • 138