iphone xCode 使用未声明的标识符 [英] iphone xCode use of undeclared identifier

查看:95
本文介绍了iphone xCode 使用未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始用 Objective-c 编程,我遇到了使用未声明的标识符‘uneImage’;你是说‘_uneImage’吗?"的问题.很多帖子都在谈论这个,但我还没有找到解决方案.

.h:

<预><代码>#进口@interface ViewController : UIViewController{UIImagePickerController *picker;}@property (weak, nonatomic) IBOutlet UIImageView *uneImage;- (IBAction)专辑:(id)sender;@结尾

.m

<预><代码>#import "ViewController.h"@interface 视图控制器 ()@结尾@实现视图控制器- (IBAction)专辑:(id)sender{选择器 = [[UIImagePickerController alloc] init];picker.delegate = self;picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;[self presentViewController:picker 动画:YES 完成:nil];}- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];[选择器dismissViewControllerAnimated:YES 完成:nil];}- (void)viewDidLoad{[超级viewDidLoad];//在加载视图后做任何额外的设置,通常是从笔尖.}- (void)didReceiveMemoryWarning{[超级 didReceiveMemoryWarning];//处理任何可以重新创建的资源.}@结尾

解决方案

当你定义一个属性 xyz 时,默认情况下它的名字会转换为 _xyz 来命名它的支持多变的.您可以使用 @synthesize name; 甚至 @synthesize name = someOtherName; 覆盖它,但不再需要使用 @synthesize.

属性本身从外部是可见的,但它不会像变量那样在作用域中引入一个不合格的名称.换句话说,你不能在没有前缀 self 的情况下使用该属性,但你可以使用它的后备变量.

长话短说,替换

uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

_uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

self.uneImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

让它发挥作用.

I just started programming in objective-c and I have a problem with "use of undeclared identifier 'uneImage'; did you mean '_uneImage'?". Lot of post speak about this but I haven't found the solution.

.h :



    #import 


    @interface ViewController : UIViewController 
    {
        UIImagePickerController *picker;
    }

    @property (weak, nonatomic) IBOutlet UIImageView *uneImage;


    - (IBAction)album:(id)sender;
    @end

.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. You can override it with @synthesize name; or even @synthesize name = someOtherName;, but the use of @synthesize is no longer required.

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.

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.

这篇关于iphone xCode 使用未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆