How to read NSComboBox auto-completed string?

  • 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
previous month may 2007 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today