Best way to make a UITextField “appear”
-
22-08-2019 - |
Question
I'd like a UITextField
to appear when a button is pressed. Unfortunately, I can't hide it in Interface Builder and then set the hidden property to NO
later because "ibtool fails with exit code 5" if you try to hide a UITextField
.
I'll try to do this in code but wondering if I may be missing something or making a grave UI error by attempting to do something like this? Or maybe it's just a bug?!?
Solution
If you can't set it to hidden in IB, you can do it programatically, with field.hidden = YES;
in your viewController's viewDidLoad
method. Then just set it back to NO
in the button's target action.
OTHER TIPS
weird, but you could just add it programmatically, and show it with some opacity animation.
Or, simply set its alpha
to 0.0. You can even really easily animate the change and it'll look really good.
I just tried adding a UITextField
in IB and checking the hidden
box, and got no crash. Of course, I'm running the 3.0 beta SDK, so it may be a bug that was fixed there. Either way, though, you should be able to just mark it as hidden and then in code set hidden = NO
. I'm not sure why it's not working for you without more information.
Yep, looks like a bug, but a possible simple workaround is to simply make it empty, i.e. give it no string value in IB
, and set that string value (via NSLocalizedString()
of course) when you want it to 'appear'.