Your mouseDown:
method is the culprit here. Instead of referencing to the comboBox1 in your NIB, you create a new instance of comboBox1 every time and tell that new instance to 'hide'. Next to leaking memory there, you probably don't want a new comboBox1 every time you click the NSTextField.
Instead use NSTextField's delegate methods to get what you want.
- (void)controlTextDidBeginEditing:(NSNotification *)obj;
- (void)controlTextDidEndEditing:(NSNotification *)obj;
- (void)controlTextDidChange:(NSNotification *)obj;
Since you're using IB I assume you got a View- or WindowController with both the txtField1 and the comboBox1. In your ViewController (or WindowController) set the ViewController as the NSTextField's delegate and tell the comboBox1 to hide in one of the delegate methods.
An example:
In your ViewController.h first declare both objects:
@property (assign) IBOutlet comboBox1 *comboBox1;
@property (assign) IBOutlet txtField1 *txtField1;
Then in your implementation:
- (void)controlTextDidBeginEditing:(NSNotification *)obj {
[comboBox1 hide];
}
Just don't forget to connect the outlets to your ViewController in Interface Builder. Also connect the delegate
outlet of the txtField1 to your Viewcontroller.