Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call method from another class in iOS?
    primarykey
    data
    text
    <p>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.</p> <p>Below is a simple example of my problem.<br> I am trying to call the method 'getName', but I am getting an error saying: “No visible @interface for 'LabelGestureRecognizer' declares the selector 'getName:'”</p> <p>ViewController.h:</p> <pre><code>@property (nonatomic, strong) UILabel *valueLabel; </code></pre> <p>ViewController.m:</p> <pre><code>- (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; } </code></pre> <p>Label.h:</p> <pre><code>@protocol LabelDelegate &lt;NSObject&gt; @required -(void) wheelDidChangeValue:(NSString *) newValue; @end @class LabelGestureRecognizer; </code></pre> <p>LabelGestureRecognizer.m:</p> <pre><code>- (NSString *) getName:(int) position { NSString *resultat = @""; switch (position) { case 0: resultat = @"Test 1"; break; case 1: resultat = @"Test 2"; break; default: break; } return resultat; } </code></pre> <p>LabelGestureRecognizer.h:</p> <pre><code> @interface LabelGestureRecognizer : UIGestureRecognizer { NSDate *previous; double current; } </code></pre> <p>Label.m:</p> <pre><code> LabelGestureRecognizer *recognizer = [[LabelGestureRecognizer alloc] init]; [self.delegate wheelDidChangeValue:[self getName:0]]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload