该属性只能通过消息传递来访问(Objective-c) [英] Property only accessible via message passing (Objective-c)

查看:47
本文介绍了该属性只能通过消息传递来访问(Objective-c)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,我无法将视图作为属性访问

For some reason I cannot access the view as a property

MyAppDelegate *APPDELEGATE=((MexicanWaveAppDelegate*)[[UIApplication sharedApplication] delegate]);
[APPDELEGATE.viewController view];
APPDELEGATE.viewController.view; //Accessing unknown 'view' component of a property

我已经能够将view作为其他视图控制器的属性来访问,并且它是文档中的一个属性.您能解释这种行为吗?

I have been able to access view as a property for other view controllers and it is a property in the doc. Can you explain this behavior?

推荐答案

问题实际上是由于我的应用程序委托.h文件( MexicanWaveAppDelegate.h )不包含有关哪种类型的信息而引起的视图控制器( MexicanWaveViewController )是.这意味着任何导入 MexicanWaveAppDelegate.h 的类都将其 MexicanWaveViewController 属性设置为不透明类型"(一种不知道其信息的类型).

The problem was actually caused because my app delegate .h file (MexicanWaveAppDelegate.h) didn't contain information about what type the view controller (MexicanWaveViewController) was. This means that any class importing MexicanWaveAppDelegate.h would have its MexicanWaveViewController property as an 'opaque type' (a type about which no information is known).

可以通过以下两种方法之一更改 MexicanWaveAppDelegate.h 来解决此问题:

This problem can be solved by changing MexicanWaveAppDelegate.h in either of the following ways:

  • 导入"MexicanWaveViewController.h"
  • 为MexicanWaveViewController提供前向声明

这篇关于该属性只能通过消息传递来访问(Objective-c)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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