开发者

Assigning a delegate programmatically

开发者 https://www.devze.com 2023-03-18 03:21 出处:网络
I am attempting to assign my view controller as the delegate to a NSTextField I created from within the application:

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

精彩评论

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