Man I am a newb, more help needed from you guys!
Ok, so I have been told that if I want to access the text value of a TextView or TextField inside of the UI module, I need to do the following:
variable = ui.TextView["viewnamehere"].text
But whenever I do this, it returns an error that says that the module has no "_getitem_" attribute or whatever. Please help! Thank you.
This post is deleted!last edited by
Let's go one step at a time. The method above wont work, because ui.TextView is a kind of class, not an object.
First, how are you creating/displaying your view? are you creating it programatically, or using the ui builder?
next, you need to get your textview object.
if you have loaded a view built in the ui editor, you will have given each subview a name, or it was generated for you.
assuming you loaded the view into a variable named
root, you can find your textview using
root['whatever_you_named_your_textview_in_the_editor']. don't literally type this in.... go check what you named the textview, and write that inside the quotes. it might be named for you, like textview1. assign it to a global variable, which simplifies things a bit.
if you created the view programatically, you probably already have a variable that points to the textview. people often place such variables inside custom classes as instance variables, which makes organizing a little easier, and safer than using globals.
so, say you have done this, and now you have a variable (lets call it
tv) which is of type TextView....
tv.textcontains the text you want.
other ways to find your textview object:
-from inside a textview delegate action, the argument to the callback will be the textview that changed. see the docs on textviews for examples.
- from inside a button action, you have to find the rootview, then traverse down again. for instance
sender.superview['whatever_you_named_your_textview'], or, if you know that the textview is the second thing added to a view, you could use
swnder.superview.subviews, etc. these methods of navigating are a little cumbersome, and require you to sort of know how the view is structured, and for complex views gets unwieldy quickly. most people, i think, when they load or create a view, store variables to the other elements that they want easy access to.