我正在继承NSTextField
MultiTextField.h
#import <AppKit/AppKit.h>
@interface MultiTextField : NSTextField {
id storedObject;
}
@property (nonatomic, retain) id storedObject;
@end
MultiTextField.m
#import "MultiTextField.h"
@implementation MultiTextField
@synthesize storedObject;
@end
存储指向对象的指针,我想“重命名”。
我使这个文本字段可编辑,并有一个代表听取controlTextDidChange:
并且工作正常:
- (void)controlTextDidChange:(NSNotification *)aNotification {
NSTextView *textView = [[aNotification userInfo] objectForKey:@"NSFieldEditor"];
NSString *theString = [[textView textStorage] string];
if([theString length] > 0 ) {
MyObject *theObject = ???; // I need access to the MultiTextField.storedObject!
[theObject setName:theString];
}
}
唯一的问题是我无法访问storedObject(请参阅if-block中的注释)。
那我该如何访问那个storedObject?
答案 0 :(得分:1)
试试这个:
MyObject *theObject = [[aNotification object] storedObject];