Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically set delegate to every UITextField
    text
    copied!<p>i'm more or less new to objective C programming, so maybe this will sound a little weird..</p> <p>i'm trying to programmatically set the delegate of a lot of UITextFields from an UIViewController that is the parent of the actual UIViewController that contains the UITextfields. Basically it the same of doing right-click on the UITextField, and setting the UIViewController as the delegate of this control. </p> <p>I've tried to loop the self.view.subview array but I only get 2 UIImageViews (i'm still trying to understand this... i think is something about using static cells but I'm confused). So the next option was to loop through all the properties of the class.</p> <p>Using a mix of codes of stackoverflow i've almost done it, but I still need to send the message to the textfield per se.</p> <pre><code>unsigned int count = 0; objc_property_t *properties = class_copyPropertyList( [self class], &amp;count ); for( unsigned int i = 0; i &lt; count; i++ ) { objc_property_t property = properties[i]; const char* propertyName = property_getName(property); NSLog( @"property: %s", propertyName ); //this is actually correctly writing the name of the properties objc_msgSend((id)GetTheObjectThroughTheName, @selector(setDelegate:), self); } </code></pre> <p>The thing is I don't know how to get the object related to the property only using the name of the property... but if i can get it and use the objc_msgsend using that object as receiver it will be solved.</p> <p>Any ideas on that?</p> <p>Thanks in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload