How to add a instance variable and use it in a custom UIButton
I created a custom UIButton like this
@interface CustomButton : UIButton {
NSString *firstLine;
NSString *secondLine;
}
@property (nonatomic, retain) NSString *firstLine;
@property (nonatomic, retain) NSString *secondLine;
@end
Custo开发者_StackOverflow社区mButton* rightButton = [CustomButton buttonWithType:UIButtonTypeDetailDisclosure];
rightButton.secondLine=@"hello";
error message is:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[UIButton setSecondLine:]: unrecognized selector sent to instance 0x43280e0'
What has to be done to fix this up? how should the instance variable added?
Try
rightButton.secondLine = @"hello";
You should override this class method
+ (id)buttonWithType:(UIButtonType)buttonType
to return an instance of your CustomButton
Well if that is all thats in your CustomButton implementation, it seems that the String is not getting placed into the Button. How are you laying out the subviews of the button?
精彩评论