Question

I have a NSComboBox that is completely standard. It has a data source set up that feeds it content, which works fine. The issue is that when the user clicks to view the list, it is starting scrolled all the way to the bottom of the list instead of the top. I found

- (void)scrollItemAtIndexToTop:(NSInteger)index

and have tried putting

[comboBox scrollItemAtIndexToTop:0];

in various places but it does not do anything. This is more annoying that I can't figure it out than anything else.

Thanks in advance.

EDIT: Code from data source:

- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
    return [[engineTypesArrayController arrangedObjects] count];
}

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index
{
    return [[[engineTypesArrayController arrangedObjects] objectAtIndex:index] valueForKey:@"title"];
}


- (NSString *)comboBoxCell:(NSComboBoxCell *)aComboBoxCell completedString:(NSString *)uncompletedString
{
    NSArray *matchingObjects = [[engineTypesArrayController arrangedObjects] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(logTenCustomizationProperty_title BEGINSWITH[c] %@)", uncompletedString]];

    if (matchingObjects && ([matchingObjects count] > 0))
    {
        return [[matchingObjects objectAtIndex:0] valueForKey:@"title"];
    }
    else
    {
        return nil;
    }
}

comboBox:indexOfItemWithStringValue is not implemented.

Was it helpful?

Solution

Adding this delegate method works:

#pragma mark - ComboBox delegate
- (void)comboBoxWillPopUp:(NSNotification *)notification
{
    NSComboBox *comboBox = [notification object];

    [comboBox scrollItemAtIndexToVisible:0];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top