I subclassed NSTextField and overwrite the textDidChange: as:
- (void)textDidChange:(NSNotification *)notification
{
// ... My own operation
}
But when I drag a input text box into my .xib
file and control drag another class to assign the delegate I found the delegate's controlTextDidChange:
method was never called.
Now tryingto solve this problem, I tried two ways al below:
I. calling super
:
- (void)textDidChange:(NSNotification *)notification
{
// ... My own operation
[super textDidChange:notification];
}
But I got an error in runtime: attempt to insert nil object from objects[0]
II. calling delegate
's method
- (void)textDidChange:(NSNotification *)notification
{
// ... My own operation
if ([self.delegate responseToSelector:@selector(controlTextDidChange:)])
{
[self.delegate ...]; // <--- Opps, something not happerned here.
}
}
What not happerned? I expected that the auto-complete should display the controlTextDidChange:
method at the position of ...
above. But it did not, actually. I typed the method directly, compilation fail because method not found.
How should I make my sub-class call the delegate normally? How should I overwrite the textDidChange:
method correctly?
Further question for Vytautas:
- I am sure I was using
NSTextField
. And I set a break point inside controlTextDidChange: method. As it was called, I should have known. - I did control-drag the text field to the delegate object, and I print delegate object in the
textDidChange:
method, it was sure that the delegate was set correctly. - The other delegate methods, such as
controlTextDidBeginEditing:
were called correctly. ButcontrolTextDidChange:
not called - I tried comment out the over-written in the subclassed
NSTextField
class, thencontrolTextDidChange:
was called. - Therefore I was quite sure that I am not overwritting the
textDidChange:
right. But I do not known how to fix it. - What made me confused mostly was that why auto-completion did not show the
controlTextDidChange:
method when I attempted to call it.
About the auto-completion, here is how it showed:
No - controlTextDidChange:
method.
2nd further reply for Vytautas:
I tried calling '[self controlTextDidChange]' but it did not work, and error occurred (as highlighted below):