Beginners problem: setKeyEquivalent in controlTextEndEditing method (NSComboBox)
Beginners problem: setKeyEquivalent in controlTextEndEditing method (NSComboBox)
- Subject: Beginners problem: setKeyEquivalent in controlTextEndEditing method (NSComboBox)
- From: Nenad Milevoj <email@hidden>
- Date: Fri, 22 Aug 2008 11:26:54 +0200
Hi,
in my project I have a window with 1 combobox and 2 buttons. Buttons
are 'Cancel' and 'Ok'. This is a sort of login
window. Combobox uses PGresult (PostgreSQL result) as data source and
has autocomplete set to YES. Button 'Ok' is disabled and is
programatically enabled if criteria is meet. Scenario is like this:
window opens, user enters login name in combobox or selects it for
list and then presses return key to validate his choice. Validation is
in method controlTextEndEditing. If his login name is found in the
result (PGresult) button 'Ok' is enabled and his key equivalent
becomes return key. My problem is that as soon as return key is
pressed for validation of entered text in combobox (when criteria is
meet) button 'Ok' is pressed too. I would like to have scenario where
user presses return key, his login name is validated, and if it is
o.k. button 'Ok' is enabled with key equivalent return key and then
user must hit return key once again to press button 'Ok'.
Code I use:
@interface AppController : NSObject {
...//other outlets and members
IBOutlet NSComboBox *users;
IBOutlet NSButton *loginOK;
}
...//some methods
@end
#import "AppController.h"
@implementation AppController
...//other methods
//part handling combobox
-(id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:
(int)index
{
int fieldNum = 1;
NSString *value;
value = [dbhelp getFieldValue:index fieldNo:fieldNum];
return value;
}
-(int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
return [dbhelp numOfRows];
}
- (void)controlTextDidEndEditing:(NSNotification *)notification
{
BOOL search = [dbhelp fieldValueInResult:[users stringValue] filedNo:
1];
if (search==YES)
{
[loginOK setEnabled:YES];
[loginsheet makeFirstResponder:loginOK];
[loginOK setKeyEquivalent:@"\r"]
}else{
//send note to user about wrong login name
}
}
@end
--Nenad
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden