gpt4 book ai didi

ios - UIButton子类: does buttonWithType: return UIButton or subclass instance?

转载 作者:行者123 更新时间:2023-11-29 04:05:00 26 4
gpt4 key购买 nike

如果我子类化 UIButton 并使用其 buttonWithType: 方法创建 button,它是否会返回一个 UIButton code> 还是子类实例?

例如:

@interface MyButton : UIButton
@end

MyButton *button = [MyButton buttonWithType:UIButtonTypeCustom];

或者我必须使用 allocinitWithFrame 来代替?

谢谢

最佳答案

抱歉,我刚刚从 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com