Search code examples
uiviewcontrollerimportuiimageviewidentifier

Use of undeclared identifier in VC but its declared in the Custom UIImageView


I'm having trouble with the use of an undeclared identifier. I have created a custom UIImageView and in it have declared a @property UILabel 'answeLbl'. I have imported the custom UIImageView.h file into my ViewController.h file but whenever i try to use the 'answerLbl' it comes up with the error 'use of undeclared identifier'. How do i stop this problem, i need to use this 'answerLbl' in my ViewController?

This is the ViewController.h

#import <UIKit/UIKit.h>
#import "NumberPadImageView.h"



@interface ViewController : UIViewController {

NumberPadImageView *numberKeyboard;

}

and then here is the custom uiiimageview => NumberPadImageView.h

#import <UIKit/UIKit.h>

@interface NumberPadImageView : UIImageView {

UILabel *answerLbl;

UIButton *oneBtn;
UIButton *twoBtn;
UIButton *threeBtn;
UIButton *fourBtn;
UIButton *fiveBtn;
UIButton *sixBtn;
UIButton *sevenBtn;
UIButton *eightBtn;
UIButton *nineBtn;
UIButton *zeroBtn;

UIButton *backBtn;
UIButton *periodBtn;
UIButton *clearAnswerFieldBtn;

}
@property (nonatomic, strong) IBOutlet UILabel *answerLbl;

-(IBAction)buttonPressed:(UIButton *)sender;
-(IBAction)backspace:(id)sender;
-(IBAction)clearAnswerLbl:(id)sender;

Solution

  • @property (nonatomic, strong) NumberPadImageView *imageView;
    

    In viewDidLoad,

    self.imageView = [[NumberPadImageView alloc]init];
    

    Access by,

    self.imageView.answerLbl
    

    and declare answerLbl as property,

    @property (nonatomic, strong) UILabel *answerLbl;