UIButton子类:does buttonWithType:返回UIButton或UIButton子类实例



如果我子类UIButton并使用其buttonWithType:方法创建button,它是否返回我UIButton或子类实例?

例如:

@interface MyButton : UIButton
@end
MyButton *button = [MyButton buttonWithType:UIButtonTypeCustom];

或者我必须使用allocinitWithFrame代替?

谢谢

对不起,我刚从苹果的文档中找到这个:

这个方法是一个方便的构造函数,用于创建具有特定配置的按钮对象。如果你子类化UIButton,这个方法不会返回你子类的一个实例。如果你想创建一个特定子类的实例,你必须直接分配/初始化按钮。

buttonWithTypeUIButtonclass method,它返回UIButton类型,虽然您的MyButton继承了UIButton,但它也不能返回MyButton类型

更多信息你可以看到我之前的回答:this

最新更新