The variable still exits. It is nil, which means it contains nothing. When you re-create the text field and assign it to the exiting variable, you are still local, not global.
I thought nil variables would be garbage collected. So if I use removeSelf it doesn’t actually remove it ? Or are you saying use removeSelf but don’t set it to nil ? Dave
Variables are just boxes that old a very small amount of data (4 bytes in most cases). If it’s something bigger like a function or a table/object, the variable just holds a pointer to the larger allocated chunk of memory. When you create an object, like a native.newTextField and stick it in a variable called myField, then what myField really contains is a number, generally printed in hexadecimal like:
0x493ba832
That is the memory address of where that native.newTextField object really exists. When you do a :removeSelf() on the object, that allocated memory is marked as being free and when you do:
myField = nil
you are erasing the memory pointer, setting myField back to nothing. However, your code still knows about myField. It knows it’s a variable that can contain something, so if you re-use it, it’s using the same name just next time it’s contents are different.
Maybe this analogy will help: You have a coffee pot you want to give a way. You put it in a box and sit it on the street. Thats the :removeSelf(). Now you put a sign on the box saying “Free to a good home”. That’s setting the variable to nil. When someone comes and takes the coffee pot, that’s the garbage collector taking the data away and you’re left with an empty box – your variable.
Awesome, ta!
Just read this and thought you might find it interesting
Overall, it depends on the needs of your app, but here are some suggestions as to things you might do to make native elements blend into your app a little better:
Use rectangles, rounded rectangles, and text objects to serve as “placeholders” for your native objects. When a user touches the placeholder, display the native object directly above while the user is editing. When the user finishes, update the placeholder to match and remove the native object.
Do transitions, etc. on your placeholder objects.
Hide the background of text boxes (with the hasBackground property) and create your own background (using a normal Corona display object) to truly make text boxes blend in with your app.
Awesome, ta!
Just read this and thought you might find it interesting
Overall, it depends on the needs of your app, but here are some suggestions as to things you might do to make native elements blend into your app a little better:
Use rectangles, rounded rectangles, and text objects to serve as “placeholders” for your native objects. When a user touches the placeholder, display the native object directly above while the user is editing. When the user finishes, update the placeholder to match and remove the native object.
Do transitions, etc. on your placeholder objects.
Hide the background of text boxes (with the hasBackground property) and create your own background (using a normal Corona display object) to truly make text boxes blend in with your app.
Does anyone have any tips on how to ensure the generated text box (placeholders) look just like the native text field would, in terms of height/width dimensions? And ensuring it works on Android and iOS ??
G
Does anyone have any tips on how to ensure the generated text box (placeholders) look just like the native text field would, in terms of height/width dimensions? And ensuring it works on Android and iOS ??
G