[英]iphone xCode use of undeclared identifier
I just started programming in objective-c and I have a problem with "use of undeclared identifier 'uneImage'; did you mean '_uneImage'?". 我刚开始在Objective-C中编程,但我遇到了“使用未声明的标识符'uneImage';您是说'_uneImage'吗?”的问题。 Lot of post speak about this but I haven't found the solution.
很多帖子都在谈论这个,但是我还没有找到解决方案。
.h : 。H :
#import
@interface ViewController : UIViewController
{
UIImagePickerController *picker;
}
@property (weak, nonatomic) IBOutlet UIImageView *uneImage;
- (IBAction)album:(id)sender;
@end
.m .m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)album:(id)sender
{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
When you define a property xyz
, by default its name is transformed to _xyz
to name its backing variable. 定义属性
xyz
,默认情况下,其名称会转换为_xyz
来命名其后备变量。 You can override it with @synthesize name;
您可以使用
@synthesize name;
覆盖它@synthesize name;
or even @synthesize name = someOtherName;
甚至
@synthesize name = someOtherName;
, but the use of @synthesize
is no longer required. ,但不再需要使用
@synthesize
。
The property itself is visible from the outside, but it does not introduce an unqualified name in the scope the same way the variables do. 该属性本身从外部是可见的,但是它不会像变量一样在范围内引入非限定名称。 In other words, you cannot use the property without prefixing it with
self
, but you can use its backing variable. 换句话说,如果不使用
self
前缀就不能使用该属性,但是可以使用其后备变量。
To make the long story short, replace 长话短说,替换
uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
with 与
_uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
or 要么
self.uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
to make it work. 使它工作。
You don't have an instance variable named uneImage
. 您没有名为
uneImage
的实例变量。 You have a property with that name and an automatically synthesized instance variable named _uneImage
. 您有一个具有该名称的属性和一个名为
_uneImage
的自动合成的实例变量。
So change: 所以改变:
uneImage.image = ...
to either: 可以:
self.uneImage.image = ... // use the property
or: 要么:
_uneImage.image = ... // use the generated instance variable
您正在访问属性,因此需要在变量前放置“ self”:
self.uneImage.image = ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.