cocos2d-objc
cocos2d-objc copied to clipboard
CCTextField textField property is always nil
I looked into the code and it seems that the property relies on the "nativeTextField" property of the CCPlatformTextField which in the current version I am using is not set in CCPlatformTextFieldIOS.
This used to work in like 3.2, but stopped working along the way... this really needs fixing!
It's now been merged into V3.4
Not entirely sure but I tried using your fix (thanks!) but it seemed like it had some problems with hiding/unhiding the uitextfield when CCtextfield was hidden/unhidden. I still have some more testing to do... busy with other things as usual... I'll just say the error can be on my side... Well this all used to work back last summer with whatever version was out then.
This is because in CCTextField the update:
is constantly setting the visibility of the UITextField based on the visibility of itself and it's parent nodes. So it's a separate issue.
Why do you want to set isHidden
on the UITextField rather than visible
on the CCTextField?
Anyway, I tried this out on a quick test project and it seems to work. My real project issue was probably caused by something else.
@RobBoluga I've had a case where I wanted to hide just the UITextField and not the whole node - basically when covering up a CCTextField with another dialog - it looked better to just remove the text rather than the whole TextField node as sometimes the node is only partially covered, and during animations where the timing of when to hide the textfield was tricky to get right. I ended up subclassing CCTextField and overriding 'update' to honour a new property of 'just hide the UITextField' after calling super.
Noticed this issue still exists when building for OSX, just copied @RobBoluga solution over to the CCPlatformTextFieldMac.m (#1373)