gpt4 book ai didi

ios - 如何添加实例变量并在自定义 UIButton 中使用它

转载 作者:行者123 更新时间:2023-11-28 17:48:26 25 4
gpt4 key购买 nike

我像这样创建了一个自定义 UIButton

@interface CustomButton : UIButton {

NSString *firstLine;
NSString *secondLine;
}
@property (nonatomic, retain) NSString *firstLine;
@property (nonatomic, retain) NSString *secondLine;

@end

CustomButton* rightButton = [CustomButton buttonWithType:UIButtonTypeDetailDisclosure];
rightButton.secondLine=@"hello";

错误信息是:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[UIButton setSecondLine:]: unrecognized selector sent to instance 0x43280e0'

要解决这个问题需要做什么?实例变量应该如何添加?

最佳答案

尝试

rightButton.secondLine = @"hello";

你应该覆盖这个类的方法

+ (id)buttonWithType:(UIButtonType)buttonType

返回自定义按钮的实例

关于ios - 如何添加实例变量并在自定义 UIButton 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2698949/

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