Reputation: 1773
I have a very simple method that allows me to specify the name of a UIButton and then set its title. I previously had the method in my main ViewController which worked fine. But then I have decided to create a new file called CustomMethods.h/m and put all of my methods in there.
As soon as I have moved the method across and #import the header into the main view controller I am getting the error message below
No visible @interface for ViewController declares the selector 'SetTitleOfButtonNamed:withTitle:'
In my CustomMethods file I have created my method as follows:
-(void)setTitleOfButtonNamed:(UIButton *)button withTitle:(NSString *)buttonTitle
{
[button setTitle:buttonTitle forState:(UIControlStateNormal)];
}
In the viewDidLoad of the main ViewController I am trying to call this method and set the button title as follows:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *btnOneTitle = @"Button 1";
[self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle]; // ERROR OCCURS HERE
}
Before I copied the method into its own file it worked perfectly. Any ideas?
Upvotes: 1
Views: 10375
Reputation: 2525
You are still calling setTitleOfButtonNamed on "self" which is the ViewController. You need to call it from the CustomMethods class that implements the method now.
[self setTitleOfButtonNamed:buttonOne withTitle:btnOneTitle];
Upvotes: 4