ios - performSelector in category of superclass fails when calling method available in specific subclass -


i have uiview category defines methods manipulate attributedtext property of uilabel , uitextview.

@implementation uiview (replaceattrtext) -(void) replaceattrtext: (nsstring *)str {     if ([self respondstoselector: @selector(setattributedtext)]) {         nsmutableattributedstring *labeltext = [self template];          // change          [self performselector:@selector(setattributedtext) withobject: labeltext];     } } @end 

respondstoselector returns false both uilabel , uitextview (although respond setattributedtext) , if setattributedtext executed directly without respondstoselector check exception raised.

when category implemented directly on uilabel (without selectors) works, unfortunately uilabel , uitextview don't have common ancestor has attributedtext property.

what doing wrong? thanks!

uilabel , uitextview not have method named setattributedtext. have method named setattributedtext:. note colon. colon part of method name. having or not represents 2 separate methods.

change code to:

-(void) replaceattrtext: (nsstring *)str {     if ([self respondstoselector: @selector(setattributedtext:)]) {         nsmutableattributedstring *labeltext = [self template];          // change          [self performselector:@selector(setattributedtext:) withobject: labeltext];     } } 

in other words, add colon both references setattributedtext.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -