ios - Unrecognized selector issue for custom UIButton -
i'm making simple uibutton subclass.
.h file:
@interface vufollowbutton : uibutton /** designated initializer @param follow highlights button if true */ + (instancetype)buttonwithfollow:(bool)follow; /* * setting bool yes highlight button , change text "following" * default "follow" */ @property (nonatomic, assign) bool following; @end .m file:
#import "vufollowbutton.h" @implementation vufollowbutton + (instancetype)buttonwithfollow:(bool)follow { vufollowbutton* followbutton = (vufollowbutton*)[uibutton buttonwithtype:uibuttontypecustom]; [followbutton settitleedgeinsets:uiedgeinsetsmake(2., 8., 2., 8.)]; followbutton.layer.bordercolor = [uicolor whitcolor]; followbutton.layer.borderwidth = 2.0f; [followbutton settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal]; followbutton.titlelabel.font = [uifont nationalboldwithsize:17]; followbutton.following = follow; return followbutton; } - (void)setfollowing:(bool)following { if (!following) { self.backgroundcolor = [uicolor clearcolor]; [self settitle:@"follow" forstate:uicontrolstatenormal]; } else { self.backgroundcolor = [uicolor blackcolor]; [self settitle:@"following" forstate:uicontrolstatenormal]; } } @end but on line followbutton.following = follow;, i'm getting:
-[uibutton setfollowing:]: unrecognized selector sent instance 0x7f9c10f809b0 if set breakpoint before line, followbutton shows vufollowbutton in variable debugger , has property called following.
i know i'm missing basic here.
you're instantiating uibutton , casting vufollowbutton. instance you're returning of type uibutton, doesn't have setfollowing: accessor method or following property. reason following property visible because you've casted type vufollowbutton.
e.g.
vufollowbutton* followbutton = (vufollowbutton*)[uibutton buttonwithtype:uibuttontypecustom]; should be:
vufollowbutton* followbutton = [vufollowbutton buttonwithtype:uibuttontypecustom];
Comments
Post a Comment