我像这样创建了一个自定义 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/