我在使用未声明的标识符方面遇到了麻烦。我创建了一个自定义的UIImageView,并在其中声明了@property UILabel'answeLbl'。我已将自定义UIImageView.h文件导入到我的ViewController.h文件中,但每当我尝试使用'answerLbl'时,它都会出现错误'使用未声明的标识符'。我如何阻止这个问题,我需要在我的ViewController中使用这个'answerLbl'?
这是ViewController.h
#import <UIKit/UIKit.h>
#import "NumberPadImageView.h"
@interface ViewController : UIViewController {
NumberPadImageView *numberKeyboard;
}
然后这是自定义uiiimageview =&gt; 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;
答案 0 :(得分:0)
@property (nonatomic, strong) NumberPadImageView *imageView;
在viewDidLoad中,
self.imageView = [[NumberPadImageView alloc]init];
访问,
self.imageView.answerLbl
并将answerLbl声明为属性,
@property (nonatomic, strong) UILabel *answerLbl;