简体   繁体   English

iPhone XCode使用未声明的标识符

[英]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.

相关问题 Xcode 5中的错误“使用未声明的标识符” - Errors in Xcode 5 “use of undeclared identifier” 错误:在Xcode中使用未声明的标识符NSOpenPanel - Error: Use of undeclared identifier NSOpenPanel in Xcode 使用xCode 4.3.3使用未声明的标识符'NSLineBreakByWordWrapping' - Use of undeclared identifier 'NSLineBreakByWordWrapping' using xCode 4.3.3 使用未声明的标识符'CJSONDeserializer'??? 带有json的Xcode - Use of undeclared identifier 'CJSONDeserializer' ??? Xcode with json Xcode“使用未声明的标识符”错误,但存在变量 - Xcode 'Use of undeclared identifier' error but variable exists xcode 上未声明的标识符 __bridge - Undeclared identifier __bridge on xcode 在iOS 8(Xcode 6)中使用未声明的标识符“GL_BGRA_EXT”错误? - Use of undeclared identifier 'GL_BGRA_EXT' error in iOS 8(Xcode 6)? XCode使用未声明的标识符,仅在打开文件时出现 - XCode use of undeclared identifier, only appears if the file is opened 在xcode中使用djinni时,“使用未声明的标识符”'noreturn' - “use of undeclared identifier” 'noreturn' when using djinni in xcode Xcode Admob单例-“使用未声明的标识符“ shared””错误 - Xcode Admob singleton - “use of undeclared identifier ”shared“” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM