锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 开源技术 / ios开源技术 / 使用未定义标识符Use of undeclared identifier
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源,禁止转载和任何形式的非法内容使用,违者必究


使用未定义标识符Use of undeclared identifier

I first created a property in my SecondViewController.h file using首先在我的SecondViewController.h文件中创建了一个属性

@property (weak, nonatomic) IBOutlet UIWebView *webView;    

And then synthesised it in the corresponding .m file using然后使用相应的.m文件合成它

@property (weak, nonatomic) IBOutlet UIWebView *webView;    

I then created a function to create a webpage using a string which the user would cast as an argument. The function:然后,我创建了一个函数来使用字符串创建网页,用户可以将其作为参数进行转换。功能:

void createWebpage(NSString *webString) {
  NSURL *url = [NSURL URLWithString:webString];
  NSURLRequest *requestUrl = [NSURLRequest requestWithURL:url];
  [webView loadRequest:requestUrl];
  }  

And where it is called.调用位置。

- (void)viewDidLoad {
    createWebpage(@"http://www.google.com");
    [super viewDidLoad];  // Do any additional setup after loading the view, typically from a nib.
  }    

However, in the last line of the function, [webView loadRequest:requestUrl];, webView produces the error "Use of undeclared identifier 'webView'. Why is this, and how can I fix it? All help appreciated.但是,在函数的最后一行[webView loadRequest:requestUrl];,webView会产生错误“使用未定义的标识符'webView'。为什么会这样,我该如何解决?所有帮助都表示赞赏。

You are declaring a property which is a available in an object. But you are declaring a simple C method:您定义属性是对象中可用的。但是你要定义了一个简单的C方法:

void createWebpage(NSString *webString) {
  NSURL *url = [NSURL URLWithString:webString];
  NSURLRequest *requestUrl = [NSURLRequest requestWithURL:url];
  [webView loadRequest:requestUrl];
  }    

This method will be executed in a "global context" but not on the object. So you can't access the objects properties.此方法将在“全局上下文”中执行,但不在对象上执行。因此您无法访问对象属性。

而是使用一种方法:

Instead use a method:

- (void) createWebpage:(NSString *)webString {
      NSURL *url = [NSURL URLWithString:webString];
      NSURLRequest *requestUrl = [NSURLRequest requestWithURL:url];
      [self.webView loadRequest:requestUrl];
  }  

And you have to use self to refer to the current object when you're accessing a property.

You can then call this method:当您访问属性时,必须使用self来引用当前对象。

然后,您可以调用此方法:

[self createWebpage:@"http://www.google.com"];

I really recommend you to read this: https://developer.apple.com/library/mac/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html

void createWebpage is not a instance method, so the instance variables (such as webView) won't be accessible from there.
You must declare the method as: -(void)createWebpage:(NSString *)webString, and call it as [self createWebPage:@"http://www.google.com"];void createWebpage不是实例方法,因此webView无法从那里访问实例变量(例如)。
您必须将方法声明为:-(void)createWebpage:(NSString *)webString,并将其命名为[self createWebPage:@"http://www.google.com"];

友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内