开发者

Assigning a delegate programmatically

I am attempting to assign my view controller as the delegate to a NSTextField I created from within the application:

replaceCell = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 60)];
[replaceCell setDelegate:(id)myViewController];

I have implemented the following methods in myViewController

- (void)controlTextDidBeginEditing:(NSNotification *)aNotification
- (void)controlTextDidEndEditing:(NSNotification *)aNotification

Neither get called. The text field is being inserted into a NSMatrix. So I tried

mapMatrix.delegate = (id)myViewController;

and implemented the following methods in myViewController

- (BOOL)textShouldBeginEditing:(NSText *)textObject;
- (BOOL)textShouldEndEditing:(NSText *)textObject;

Again, neither gets called. I would very much appreciate any input.

Ultimately what I'm trying to do is intercept when the user presses the tab key to advance from one cell in the matrix to 开发者_如何学Pythonthe next. Sorry, should have stated that to begin with.


[replaceCell setDelegate:self];

or

replaceCell.delegate=self;

self in this context is your current viewcontroller where this code appears.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜