2

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 the next. Sorry, should have stated that to begin with.

  • 1
    Are you sure `myViewController` has been set and is different from `nil` **before** you set it as the text field’s delegate? –  Jul 06 '11 at 09:45
  • Further to @Bavarious's comment, in which method are you creating the text field? – Rob Keniger Jul 06 '11 at 23:50
  • Yes, definitely sure it isn't nil. The method, where the text fields are created, is in a different object than myViewController. I tried using self as indicated below and placed the delegate methods in the same object, but it still didn't work. – Scott Henderson Jul 07 '11 at 03:43

1 Answers1

0
[replaceCell setDelegate:self];

or

replaceCell.delegate=self;

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

TechZen
  • 64,370
  • 15
  • 118
  • 145