I have a custom button which I want to assign a string and then pass the button as a parameter in a @selector. For this reason, in the header files CustomButton I put a property “name”. However, when I assign the string to button, I get this error.
'NSInvalidArgumentException', reason: '-[UIButton setName:]: unrecognized selector sent
to instance 0x8484560'
What does it mean?
The code in CustomButton.h:
@interface CustomButton : UIButton
@property (nonatomic, strong)NSString * name;
@end
The code in CustomButton.m:
@synthesize name;
In MapViewController.m
CustomButton *rightButton = [CustomButton buttonWithType:UIButtonTypeInfoLight];
NSLog(@"The button is %@", rightButton);
/*The button is <UIButton: 0x8484560; frame = (0 0; 18 19); opaque = NO; layer =
<CALayer: 0x8484670>>*/
rightButton.name = self.nameTable; //the error is here
Change the button type to
UIButtonTypeCustom.