相关疑难解决方法(0)

子类UIButton添加属性

我想子类UIButton添加一些我需要的属性(不是方法...只有属性).

这是我的子类的代码:

//.h-----------------------
@interface MyButton : UIButton{
    MyPropertyType *property;
}

@property (nonatomic,retain) MyPropertyType *property;
@end

//.m--------------------------
@implementation MyButton
@synthesize property;

@end
Run Code Online (Sandbox Code Playgroud)

在这里我如何使用该类:

MyButton *btn = ((MytButton *)[MyButton buttonWithType:UIButtonTypeRoundedRect]);
btn.property = SomeDataForTheProperty;
Run Code Online (Sandbox Code Playgroud)

从哪里获得此错误:

 -[UIRoundedRectButton setProperty:]: unrecognized selector sent to instance 0x593e920
Run Code Online (Sandbox Code Playgroud)

因此,从ButtonWithType我获得一个UIRoundedRectButton,(Mybutton *)不能施展它...我需要做什么来获得一个MyButton对象?是-init唯一的解决方案?

谢谢!

iphone objective-c uibutton ios

34
推荐指数
2
解决办法
2万
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1

uibutton ×1