I have 2 classes. 1st one is Label, another one is LabelGestureRecognizer. In the LabelGestureRecognizer have a method called getName, and i want call the method through the Label class.
Below is a simple example of my problem.
I am trying to call the method ‘getName’, but I am getting an error saying:
“No visible @interface for ‘LabelGestureRecognizer’ declares the selector ‘getName:’”
ViewController.h:
@property (nonatomic, strong) UILabel *valueLabel;
ViewController.m:
- (void)viewDidLoad
{
valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 366, 320, 50)];
valueLabel.textAlignment = UITextAlignmentCenter;
valueLabel.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:valueLabel];
}
- (void) wheelDidChangeValue:(NSString *) newValue {
self.valueLabel.text = newValue;
}
Label.h:
@protocol LabelDelegate <NSObject>
@required
-(void) wheelDidChangeValue:(NSString *) newValue;
@end
@class LabelGestureRecognizer;
LabelGestureRecognizer.m:
- (NSString *) getName:(int) position
{
NSString *resultat = @"";
switch (position) {
case 0:
resultat = @"Test 1";
break;
case 1:
resultat = @"Test 2";
break;
default:
break;
}
return resultat;
}
LabelGestureRecognizer.h:
@interface LabelGestureRecognizer : UIGestureRecognizer
{
NSDate *previous;
double current;
}
Label.m:
LabelGestureRecognizer *recognizer = [[LabelGestureRecognizer alloc] init];
[self.delegate wheelDidChangeValue:[self getName:0]];
When you are using
selfinLabel.m, that represents the current class object. If you need to representLabelGestureRecognizerobject, you need to use that in place ofselfas,Also you should declare the following in your
LabelGestureRecognizer.hfile as,Your error message is saying that it is not able to see the declaration of
getNamemethod inLabelGestureRecognizer.hclass file.