uiwebview - Change iOS components value dynamically (Generic Programming) -
to make generic code, need dispatch value component, whatever type of component (uislider
,uitextfield
,uiwebview
etc ...)
problem : sometimes,uicontrol
manage object type (nsstring * uitextfield
), , primitive type (float uislider).
my dispatcher class dispatch value component knows : * setter use set value component (example : @selector(settext:)
foruitextfield
) * value set
it uses kvo/kvc , can manipulate (id) type (so objects type because id can't hide primitive type).
how dispatch float value uislider generic ? way achieve create category onuislider
manages object type , inherit uislider override setvalue:animated
, "value" uses object type setter (setobjectvalue:
, "objectvalue") :
uislider+dataobjet.h :
@interface uislider (dataobject) @property (nonatomic, strong) nsnumber *objectvalue; @end @interface mfslider : uislider @end
uislider+dataobject.m :
#import "uislider+dataobject.h" #import <objc/runtime.h> static void * objectvalueidentifier = &objectvalueidentifier; @implementation uislider (dataobject) -(void)setobjectvalue:(nsnumber *)value{ objc_setassociatedobject(self, &objectvalueidentifier, value, objc_association_retain_nonatomic); } -(nsnumber *)objectvalue { return objc_getassociatedobject(self, &objectvalueidentifier); } @end @implementation mfslider -(void)setvalue:(float)value animated:(bool) animated{ [super setvalue:value animated:animated]; [self setobjectvalue:@(value)]; } -(float)value { return [[self objectvalue] floatvalue]; } @end
it works, won't inheritsuislider
allow users use basicuislider
insteadmfslider
in storyboards... , can't override basic implementation ofuislider
methods in category (without looping ...)
any idea ? thx
Comments
Post a Comment