views:

72

answers:

2

Hi,

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

CustomButton* 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 ?

A: 

Try

rightButton.secondLine = @"hello";

You should override this class method

+ (id)buttonWithType:(UIButtonType)buttonType

to return an instance of your CustomButton

kubi
+ (id)buttonWithType:(UIButtonType)buttonType{ return (CustomButton*)[super buttonWithType:buttonType];}I overide like this. I get the error.
thndrkiss
Casting won't do it, since you aren't actually creating an instance of your custom button. You should either recreate the detail disclosure button yourself or not subclass the button and modify the `UIButton` through the existing methods/properties.
kubi
A: 

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?

Tilo Mitra