如果我子类化 UIButton
并使用其 buttonWithType:
方法创建 button
,它是否会返回一个 UIButton
code> 还是子类实例?
例如:
@interface MyButton : UIButton
@end
MyButton *button = [MyButton buttonWithType:UIButtonTypeCustom];
或者我必须使用 alloc
和 initWithFrame
来代替?
谢谢
最佳答案
抱歉,我刚刚从 Apple 的文档中找到了此内容:
This method is a convenience constructor for creating button objects with specific configurations. It you subclass UIButton, this method does not return an instance of your subclass. If you want to create an instance of a specific subclass, you must alloc/init the button directly.
关于ios - UIButton子类: does buttonWithType: return UIButton or subclass instance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15402599/