[英]AppDelegate's property not accessible
I create a property countryNameInitials
as NSMutableArray in AppDelegate.m interface and synthesize it. 我在AppDelegate.m接口中创建一个属性
countryNameInitials
作为NSMutableArray并合成它。 The purpose is to store global data to display in table view. 目的是存储全局数据以在表视图中显示。 In the table view controller:
在表视图控制器中:
#import "AppDelegate.h"
...
@implementation
#define AppDelegate [[UIApplication sharedApplication] delegate]
...
The problem is that I cannot use AppDelegate.countryNameInitials
to access the data. 问题是我不能使用
AppDelegate.countryNameInitials
来访问数据。 Any idea? 任何想法?
The fact is that 事实是这样的
[[UIApplication sharedApplication] delegate]
will give you a generic UIApplcationDelegate
; 会给你一个通用的
UIApplcationDelegate
; while you need your MyOwnAppDelegate
(don't know how you called it) type to be able to use your countryNameInitials
property. 虽然你需要你的
MyOwnAppDelegate
(不知道你怎么称呼它)类型才能使用你的countryNameInitials
属性。 So, try with: 所以,尝试:
#define AppDelegate ((MyOwnAppDelegate*)[[UIApplication sharedApplication] delegate])
then 然后
AppDelegate.countryNameInitials
should work. 应该管用。
(I would not use the same name for the class and the macro, though). (但我不会为类和宏使用相同的名称)。
The problem of accessing countryNameInitials
is due to I declared the property in AppDelegate.m. 访问
countryNameInitials
的问题是由于我在AppDelegate.m中声明了该属性。 After I move it to AppDelegate.h, errors are gone. 我将它移动到AppDelegate.h后,错误消失了。
Side notes: 1. AppDelegate
as the identifier name works for me. 附注:
AppDelegate
作为标识符名称适合我。 Naming conflicts suggested by @Vakio is not relevant. @Vakio建议的命名冲突无关紧要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.