How to read NSComboBox auto-completed string?
How to read NSComboBox auto-completed string?
- Subject: How to read NSComboBox auto-completed string?
- From: Joachim <email@hidden>
- Date: Tue, 29 May 2007 10:49:32 +0200
I'm having troubles reading the auto-completed string in my
NSComboBox, and I haven't been able to find a solution in the archives.
I'm using an internal list, and everything seems to behave normally.
When I'm typing in the field, however, I can't read the full, auto-
completed string in my -controlTextDidChange: method.
If I have a "First" and "Second" item in my list, for example, this
is what I get as I'm typing "Sec". The "First" item is selected per
default, and the value of the NSComboBox is bound to an object
(Continuously Updates Value):
cell value:S, stringValue:S, objectValueOfSelectedItem:First,
boundObject:S
cell value:Se, stringValue:Se, objectValueOfSelectedItem:Second,
boundObject:Se
cell value:Sec, stringValue:Sec, objectValueOfSelectedItem:Second,
boundObject:Sec
Notice in the first line that objectValueOfSelectedItem: is "hanging
on" to the previously selected value despite that the correct, full,
auto-completed string is shown in the UI.
In fact, objectValueOfSelectedItem: is always one "step" behind. So
if I were to select the field and type F, objectValueOfSelectedItem:
would still return "Second".
This is my code:
- (void)awakeFromNib
{
[comboBox addItemsWithObjectValues:[NSArray
arrayWithObjects:@"First", @"Second", nil]];
[comboBox setCompletes:YES];
}
- (void)controlTextDidChange:(NSNotification *)aNotification
{
NSComboBox *box = [aNotification object];
NSString *str = [box indexOfSelectedItem] > -1 ? [box
objectValueOfSelectedItem] : [box stringValue];
NSLog (@"cell value:%@, stringValue:%@, objectValueOfSelectedItem:%@,
boundObject:%@",
[[box cell] stringValue], [box stringValue], str,
[myBoundObject string]);
}
Any ideas as to how I can read the auto-completed string shown in the
UI?
Thanks in advance,
Joachim
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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