views:

830

answers:

5

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?!?

+1  A: 

weird, but you could just add it programmatically, and show it with some opacity animation.

CiNN
A: 

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.

BJ Homer
I tried it with the 2.2 SDK and got the same result, so yes, perhaps it is a bug.
Perspx
+1  A: 

Or, simply set its alpha to 0.0. You can even really easily animate the change and it'll look really good.

Kenneth Ballenegger
This does appear to be more elegant. Animating the HIDDEN property doesn't seem to work. It's all or nothing. so using a combo of HIDDEN and Alpha keeps the keeps it hidden and prevents it from responding to touches until it's activated. thx.
Meltemi
A: 

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'.

Jim Dovey
+4  A: 

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.

eliego