是否可以从其属性访问父对象?
在这个简单的应用程序中,我有一个响应按键事件的窗口。我希望名为“window”的属性对象在事件发生时将其父对象“AppDelegate”变量“upKeyPressed”设置为一个值。有没有可能?
AppDelegate.h:
@interface MyWindow : NSWindow
@end
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
BOOL upKeyPressed;
}
@property (assign) IBOutlet MyWindow *window;
@end
AppDelegate.m 文件:
@implementation MyWindow
- (void)moveUp:(id)sender
{
// here I want to set upKeyPressed value to YES with a kind of:
self.parentObject->upKeyPressed = YES; // *** fantasy command
}
@end
@implementation AppDelegate
...
@end