views:

679

answers:

2

Hi, I have been told that to access a UITextField in the setup i have with my app, i have to use a subView whatever this is (in a noob at objectivec) and i was given this

[subview isKindOfClass:[UITextField class]]

Where do i put this? And how can i use it to set the value of my UITextField? :D

Thanks!

Update: I want to set the value of my textfield, in the function that is called after my URLScheme - the scheme bit works as i have alerted out the url.. this is cool, now i need to set a textfield with a string?

A: 

This is still very little useful context, but you most likely want to create an outlet to your text field and just set the value using that reference (with the text property).

Ciarán Walsh
A: 

Iterating through subviews and choosing based on type is not generally considered good design practice. You should reconsider how this is structured to have explicit access to the UITextField you want to access. Doing this with Apple's private classes in particular will deny you access to the App Store. At any rate, here's how you'd do what you want:

for(UIView *subview in myParentView){
    if([subview isKindOfClass:[UITextField class]])
        [(UITextField *)subview setText:@"MyString"];
}
Mike
so this will most likely reject my app update? :(
tarnfeld
If you're doing this with Apple's classes, potentially. If not then you probably won't have an issue.
Mike
This is bad practice and should not be necessary at all! You should be able to create a direct outlet to your control from your class.
Ciarán Walsh
To whoever down-voted: I provided a clear answer to the question, and provided a caveat that the questioner probably shouldn't do it. The answer shouldn't be down-voted for answering the question, regardless of whether it is bad practice or not.
Mike
ok, is this ^^^ using apple's classes?
tarnfeld
That depends on what `myParentView` is. If `myParentView`'s class name begins with UI, then it is an Apple class.
Mike
UIWebView? I assume so
tarnfeld
If it's a UIWebView, then this would probably not be accepted by Apple. Are you trying to modify text on a page?
Mike