问题描述
我正在尝试在 MyThing.m 中声明另一个窗口
I'm trying to declare another window in MyThing.m
@property (nonatomic, strong) UIWindow *window;
但是得到这个错误
在类扩展中非法重新声明属性MyThing"(属性必须是 'readwrite',而它的主要属性是必须是只读")
如果我将窗口重命名为其他名称,则可以.这是为什么?窗口是否意味着在 AppDelegate.h 中声明一次?
If I rename window to something else, it is OK. Why is that? Is window meant to be declared once in the AppDelegate.h ?
推荐答案
我搞清楚了,和AppDelegate.h中声明的window属性无关
I figure out the problem, it has nothing to do with the window property declared in AppDelegate.h
问题是MyThing符合UIApplicationDelegate,而UIApplicationDelegate协议声明了一个属性
The problem is MyThing conforms to UIApplicationDelegate, and UIApplicationDelegate protocol declare a property
@property (nonatomic, retain) UIWindow *window NS_AVAILABLE_IOS(5_0);
所以我们必须做任何一个
So we must do either of these
MyThing.h(就像 AppDelegate.h 那样)
MyThing.h (like AppDelegate.h does)
@interface MyThing : NSObject <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
@end
或
MyThing.m(合成协议中声明的window属性)
MyThing.m (synthesize the window property declared in protocol)
@implementation WYNAppDelegate
@synthesize window;
@end
这篇关于不能声明另一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!