cocoa - "Building a Text Editor in 15 Minutes"引用示例不起作用

标签 cocoa nstextview nsdocument

我正在尝试使用 NSDocument,所以我尝试了 Building a Text Editor in 15 Minutes文本系统概述引用中的示例。

我对建议的代码进行了一些更改,例如使用属性和合成来代替声明和定义访问器方法。

我按照引用文献中编写的每个步骤进行操作,但无法实现第 5 步:

If it is not already open, double-click MyDocument.xib to open the document window in Interface Builder. From Xcode, drag the MyDocument.h file icon onto the document window of MyDocument.xib. This step informs the MyDocument.xib file that the MyDocument object interface now has an outlet variable named textView.

当我编译时,它在 NSDocument 的子类中给出了以下警告:

myDocument may not respond to setString

MyDocument 窗口没有出现,并且每次我尝试执行它时控制台中都会出现此消息:

-[MyDocument string]: unrecognized selector sent to instance 0x215970

谁能告诉我哪里可能错了?我正在尝试在 Snow Leopard 上运行它...要检查代码,您也可以从 here 下载它.

最佳答案

I am trying to work on NSDocument, so I tried the Building a Text Editor in 15 Minutes example in the Text System Overview reference.

I did some changes to code which was suggested, such as used property and synthesize in place of declaring and defining accessor methods.

我知道这已经很老了,但是该示例使用了 ivar NSAttributedString *mString; 因此您需要更改名称或使用类似以下内容:-

@property(copy, getter=string, setter=setString:) NSAttributedString *mString;

关于cocoa - "Building a Text Editor in 15 Minutes"引用示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2238641/

相关文章:

objective-c - NSImageCell:设置工具提示

iphone - 使用 Cocoa 框架,当设置标签时,显式转换为 NSString 可以工作,但 stringValue 会引发异常。为什么?

objective-c - 如何查看哪些对象保留了另一个特定对象

cocoa - 禁用 NSTextField 中的 Option-Enter 换行符?

macos - 撤消/重做菜单项不适用于基于文档的应用程序 OSX 10.7

cocoa - 电子签名 Mac OS X

cocoa - 捕获 NSTextView 而不是 NSTextField 的 TextDidChange 或 DidEndEditing

cocoa - NSTextView 判断 NSTextAttachment 是否存在

objective-c - 如何实现 NSDocument 方法 -canCloseDocumentWithDelegate :shouldCloseSelector:contextInfo: in Swift?

objective-c - 关闭文档时在 document.m 中调用的方法