Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSDocument窗口控制器和出口实例化_Objective C_Cocoa_Nstextview_Nswindowcontroller_Document Based - Fatal编程技术网

Objective c NSDocument窗口控制器和出口实例化

Objective c NSDocument窗口控制器和出口实例化,objective-c,cocoa,nstextview,nswindowcontroller,document-based,Objective C,Cocoa,Nstextview,Nswindowcontroller,Document Based,我有一个文档窗口控制器的实例,它似乎是一个奇怪的问题。我有一个基于文档的应用程序,其自定义窗口控制器是从NSDocument main类的重写MakeWindowController方法初始化的: - (void)makeWindowControllers { docWinController = [[DocumentWindowController alloc] initWithWindowNibName:@"MainDocument" owner:self]; [self

我有一个文档窗口控制器的实例,它似乎是一个奇怪的问题。我有一个基于文档的应用程序,其自定义窗口控制器是从NSDocument main类的重写
MakeWindowController
方法初始化的:

- (void)makeWindowControllers
{
     docWinController = [[DocumentWindowController alloc] initWithWindowNibName:@"MainDocument" owner:self];
     [self addWindowController:docWinController];
}// end makeWindowControllers
主应用程序窗口包含一个NSTextView对象,该对象在文件所有者(上面的窗口控制器)中具有相应的出口。我有一个通过菜单项调用的操作,应该设置文本视图textStorage对象的内容

现在,当发送者是(例如)窗口中的一个按钮时,该操作按预期工作,但当发送者是菜单项时,该操作不工作。我希望这是一个实例化问题,但令人费解的是,在操作中提供以下行:

[[[textView textStorage] mutableString] appendFormat:@"Some text...%@\n", self];
返回两个不同的窗口控制器实例id,具体取决于发件人(界面按钮或菜单项)。在一种情况下(菜单项),NSLog会显示:

-[DocumentWindowController myAction:] [L119]: Some text...<DocumentWindowController: 0x100195870>
-[DocumentWindowController myAction:[L119]:一些文本。。。
在另一种情况下(按钮):

-[DocumentWindowController myAction:[L119]:一些文本。。。

我做错了什么?

MainDocument.nib中文件所有者的类型是什么?您正在将
self
(文档)传递给
-initWithWindowNibName:owner
,但您说所有者是窗口控制器。您的配置似乎有些奇怪,但我无法从您最初的问题中分辨出它是什么。
-[DocumentWindowController myAction:] [L119]: Some text...<DocumentWindowController: 0x113e72120>