如果我继承了UIButton的子类并使用它的buttonWithType:方法来创建button,它会返回一个UIButton还是一个子类实例?
例如:
@interface MyButton : UIButton
@end
MyButton *button = [MyButton buttonWithType:UIButtonTypeCustom];或者我必须使用alloc和initWithFrame?
谢谢
发布于 2013-03-14 16:01:56
buttonWithType是UIButton的class method,它返回UIButton类型,虽然您的MyButton继承了UIButton,但也不能返回MyButton类型
更多信息你可以在前面看到我的答案:this
发布于 2013-03-14 14:28:05
抱歉,我刚从苹果的文档中找到了这个:
此方法是一个方便的构造函数,用于创建具有特定配置的按钮对象。如果你是UIButton的子类,这个方法不会返回你的子类的实例。如果你想创建一个特定子类的实例,你必须直接分配/初始化按钮。
https://stackoverflow.com/questions/15402599
复制相似问题