6

I have a custom UITextField used for validating for non empty input, correct emails, passwords bigger than x characters etc.

The UITextField has a delegate to itself, since I do all the validation on the text field object itself. Not sure if this is the problem.

This custom UITextField is created in the .XIB file.

The text field sometimes locks the application when editing the text field itself. It also usually locks up when I press the "Next" button on the keyboard (for going to the next text field that needs to be filled).

Xcode doesn't give back an error (such as a loop-error, which I was assuming it was), the application just locks up. This doesn't happen all the time, but usually, if I stress test it with text, then press "Next", it's likely to lock up.

The app doesn't crash...it doesn't go back to the main screen, but it really just locks up, and stays unresponsive.

Any ideas? Let me know if you need more info to figure this out. I'm at a loss at the moment.


edit: Solved, apparently it's not a good idea to set a UITextField's delegate to itself. What I ended up doing is creating a separate class that deals specifically as being the delegate for the UITextField and doing all the logic in that class. That class would also have a property connected to the text field it is a delegate for.

Alex
  • 7,432
  • 20
  • 75
  • 118
  • I think you are blocking main thread and app UI becomes unresponsive. Post code where validation is done – nsinvocation Feb 11 '13 at 15:44
  • 2
    This will answer your question: http://stackoverflow.com/questions/1747777/self-delegate-self-whats-wrong-in-doing-that – trojanfoe Feb 11 '13 at 15:46
  • @trojanfoe - thanks. I'll give that a try. Could there be a reason why this particular problem only appears on iPhone 5/iOS 6.0, but doesn't happen on iPhone 4/iOS 6.0? – Alex Feb 11 '13 at 15:53
  • No, the same version of iOS should behave the same regardless of platform. – trojanfoe Feb 11 '13 at 15:54
  • @trojanfoe - ok. I will try to separate that delegate first. For me, it only locks up when testing on an iPhone 5. iPhone 4 works fine. – Alex Feb 11 '13 at 15:58
  • @trojanfoe Thanks. That solved the problem. I'm still puzzled as to why it wasn't locking on iPhone 4, but it was on iPhone 5. – Alex Feb 12 '13 at 09:52
  • For me it was working on simulator and iPad 2, but not iPad Air... strange – Daniel Jun 12 '14 at 14:02

1 Answers1

8

I'll also write the answer here:

Apparently it's not a good idea to set a UITextField's delegate to itself, because it can end up going into a loop.

What I ended up doing is creating a separate class that deals specifically as being the delegate for the UITextField and doing all the logic in that class. That class would also have a property connected to the text field it is a delegate for.

Alex
  • 7,432
  • 20
  • 75
  • 118