I have several textfields (and labels) in my XIB and at some point in my application I build dynamicaly a string which contains a control name (i.e. one of the textfields).
How can I refer to the actual textfield using the string I created that holds the name of the textfield.
For example, I have txt1 , txt2, txt3, txt4 as UITextFields
and i have a string (str) that contains one of the fields above names (str =”txt3″)
then i want to change the content of the uitextfield txt3 since str have “txt3”
at this point.
How do I cast from the string to the actual control?
If the
UITextFields all have a backing property then you can use KVC to get a reference to the control and then you just use it as normal.Side note
Although you have not mentioned the source of
str@JefferyThomas raises a very valid point about not trusting use input that has not been validated.