Objective c NSTextView没有';t调用controlTextDidChange:

Objective c NSTextView没有';t调用controlTextDidChange:,objective-c,class,delegates,text-editor,nstextview,Objective C,Class,Delegates,Text Editor,Nstextview,我有一个类(“TextEditorViewController”),其中有一个NSTextView(“textView”)对象。我已将其与.xib文件中的NSTextView连接。这里是我的.h文件: #import <Foundation/Foundation.h> @interface TextEditorViewController : NSObject { IBOutlet NSTextView *textView; // connected i

我有一个类(“TextEditorViewController”),其中有一个NSTextView(“textView”)对象。我已将其与.xib文件中的NSTextView连接。这里是我的.h文件:

#import <Foundation/Foundation.h>

@interface TextEditorViewController : NSObject {
    IBOutlet NSTextView *textView;           // connected in MainMenu.xib
    IBOutlet NSTextField *displayCharacters; // connected in MainMenu.xib
}

@end
但是,当我在NSTextView中更改文本时,它不会调用controlTextDidChange:! 为什么?


谢谢你的回答!=)

将代理部分移动到viewDidLoad。

为什么不把它放到viewcontroller中?

在新项目中重建文件后,它就工作了。似乎是文件管理配置问题。

您的意思是awakeFromNib?Mac OS X不存在viewDidLoad。我尝试了从NIB唤醒,但仍然无法工作:(抱歉,我以为这是关于iOS的。没什么…我在controlTextDidChange:中调用了NSLog,但没有输出。当我在该方法中设置断点时,如果我更改文本,它不会停止。哈哈,它不可能是iOS,因为NSTextField&NSTextView:dp请将断点设置为setDelegate。让我们看看Textview是否已经存在。
#import "TextEditorViewController.h"    

@implementation TextEditorViewController

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSLog(@"applicationDidFinishLaunching called"); // printed to the debugger
    [textView setDelegate:(id)self];
}

- (void)controlTextDidChange:(NSNotification *)obj {
    NSLog(@"controlTextDidChange called"); // don't printed to the debugger ???
    [displayCharacters setIntValue:[[textView string] length]];
}

@end