我試圖使它在我的應用程序中的每個UIControl
(UIButton
,UISlider
等)都具有特殊的額外屬性,我將它們添加到它們中。將屬性添加到我的所有UIControls
我試圖通過創建一個UIControl
類別並在需要時將其導入,但我遇到了問題。
這是我的代碼。
我的setSpecialproperty
方法被調用,但它似乎被調用在一個無限循環,直到應用程序崩潰。
你能告訴我什麼我做錯了或建議一個更聰明的方法來添加一個屬性到我所有的UIControls
?
@interface UIControl (MyControl)
{
}
@property(nonatomic,strong) MySpecialProperty *specialproperty;
-(void)setSpecialproperty:(MySpecialProperty*)param;
@end
////////
#import "UIControl+MyControl.h"
@implementation UIControl (MyControl)
-(void)setSpecialproperty:(MySpecialProperty*)param
{
self.specialproperty=param;
}
///////////////
#import "UIControl+MyControl.h"
@implementation ViewController
UIButton *abutton=[UIButton buttonWithType:UIButtonTypeCustom];
MySpecialProperty *prop=[MySpecialProperty alloc]init];
[abutton setSpecialproperty:prop];
您不需要創建setter方法。編譯器已經爲你做到了。只要打電話吧! – CainaSouza 2013-02-26 12:13:48