我不明白为什么beginSheetModalForWindow不能工作。
以下是MyAppDelegate.h的内容
@interface MyAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
@end
MyAppDelegate.m
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
}
@end
在我的AppController.m中有以下几行代码
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"Alert."];
[alert beginSheetModalForWindow:window
modalDelegate:self
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
问题是我得到一个错误:使用未声明的标识符窗口。
我错过了什么?
发布于 2011-10-15 20:54:28
“‘window”是属于你的MyAppDelegate实例的一个变量。为了在AppController中使用相同的窗口变量,AppController需要一个对窗口的引用。我不确定这两个类之间的关系,但通常当一个类需要为另一个类提供对它的一个实例变量的引用时,引用是在方法调用中传递的。例如,您可以向窗口添加一个setWindow:方法,然后让MyAppDelegate调用该方法,并提供变量'window‘。
https://stackoverflow.com/questions/7779358
复制相似问题