从另一个 Class 访问 属性,分离 XIB
Access Property from Another Class, separate XIB
这可能是一个简单的问题,但请耐心等待,我是新手,只是在试验。 MacOS,不是 iOS,假设我有两个单独的 XIB 文件(MainMenu.xib 和 AnotherWindow.xib)。我正在使用 MainMenu.xib 中的文件菜单打开 AnotherWindow.xib,并在打开时禁用文件菜单:
- (IBAction)OpenAnotherWindow:(id)sender {
if (!anotherWindow) {
anotherWindow = [[AnotherWindow alloc] initWithWindowNibName:@"AnotherWindow"];
}
[anotherWindow showWindow:self];
[self.MenuItem setEnabled:NO];
在 AnotherWindow.xib 中,我想在关闭时重新启用文件菜单:
- (void)windowWillClose:(NSNotification *)aNotification {
[self.MenuItem setEnabled:YES];
}
我遇到的问题是我无法从第二个 class 访问 MenuItem,因为它是 MainMenu.xib 的一部分 - 所以我只收到错误消息:属性 not found在 [self.MenuItem setEnabled:YES] 类型的对象上;在 AnotherWindow.xib
所以我想我的问题是:我怎样才能像
一样访问 属性
@property (weak) IBOutlet NSMenuItem *MenuItem;
那是在我的 MainMenu.xib 来自 AnotherWindow.xib。
不是手动启用和禁用菜单项,而是覆盖 class 中包含 OpenAnotherWindow
IBAction 的函数 validateUserInterfaceItem
。
validateUserInterfaceItem
函数将 NSValidatedUserInterfaceItem
类型的项目作为参数。检查项目的操作是否为 OpenAnotherWindow
。如果是,请检查 anotherWindow
是否打开。如果它是打开的,return false,这将禁用菜单项。如果 window 未打开,则 return 为真,这将启用菜单项。我的 Objective-C 生锈了,所以我没有适合您的代码清单。
这可能是一个简单的问题,但请耐心等待,我是新手,只是在试验。 MacOS,不是 iOS,假设我有两个单独的 XIB 文件(MainMenu.xib 和 AnotherWindow.xib)。我正在使用 MainMenu.xib 中的文件菜单打开 AnotherWindow.xib,并在打开时禁用文件菜单:
- (IBAction)OpenAnotherWindow:(id)sender {
if (!anotherWindow) {
anotherWindow = [[AnotherWindow alloc] initWithWindowNibName:@"AnotherWindow"];
}
[anotherWindow showWindow:self];
[self.MenuItem setEnabled:NO];
在 AnotherWindow.xib 中,我想在关闭时重新启用文件菜单:
- (void)windowWillClose:(NSNotification *)aNotification {
[self.MenuItem setEnabled:YES];
}
我遇到的问题是我无法从第二个 class 访问 MenuItem,因为它是 MainMenu.xib 的一部分 - 所以我只收到错误消息:属性 not found在 [self.MenuItem setEnabled:YES] 类型的对象上;在 AnotherWindow.xib
所以我想我的问题是:我怎样才能像
一样访问 属性@property (weak) IBOutlet NSMenuItem *MenuItem;
那是在我的 MainMenu.xib 来自 AnotherWindow.xib。
不是手动启用和禁用菜单项,而是覆盖 class 中包含 OpenAnotherWindow
IBAction 的函数 validateUserInterfaceItem
。
validateUserInterfaceItem
函数将 NSValidatedUserInterfaceItem
类型的项目作为参数。检查项目的操作是否为 OpenAnotherWindow
。如果是,请检查 anotherWindow
是否打开。如果它是打开的,return false,这将禁用菜单项。如果 window 未打开,则 return 为真,这将启用菜单项。我的 Objective-C 生锈了,所以我没有适合您的代码清单。