Search code examples
iphoneiossafariuipickerview

Custom PickerView froze up (With sample project)


Background: I have been wanting a PickerView that is exactly matches that of Safari. I looked through many Gits and found none that work quite as exactly. I decided to build my own. It is complete now, but there is a bug that would not go away.

Problem: If you run the sample project you will be greeted with 2 text fields.

  1. Tap on one of the textfields - it brings up the BTPickerView. Everything works just as you would expect.
  2. Choose the fourth choice, then press done.
  3. Tap on the same textfield. This time, the debug log will show you that you have executed an infinite loop, which freezes the app.

Question: What did I do to cause it? And how do I fix it?

I have tried everything to boil it down. It comes down to this and I could not go any further. Please advise.


Edit: Here is the sample code you can download in case anyone missed the blue link above.


Solution

  • The issue seems to be with the constraints in BTPickerLabel. If you temporarily disable the constraints from BTPickerLabel, code works fine. Enforcing constraint might trigger the reloading of entire picker view infinitely. I hope it should help you to fix the problem.