1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

NSComboBox Help

Discussion in 'Mac Programming' started by Khanjan, Jul 2, 2009.

  1. macrumors newbie

    Hey all,

    I am new to Objective C and I am trying to build an interface for a pipeline software. So, what I want to do is, run the software and display the output files. I am trying to display the output files in a NSComboBox. When the RUN button is pressed, whatever files are created showed by visible in ComboBOx and the user can select any one to view it. I saw the Simple NSComboBox example - Developer Tools, but could not figure out how to do the same. I included all the NSComboBox methods , but am unable to populate it. Can explain what am I missing out or send me the link to some tutorial.

    Thanks in advance,
  2. Moderator emeritus


    Post your code. Hard to tell what's wrong without it. Also double-check your IB connections.
  3. macrumors newbie

    (IBAction)rundiya: (id)sender

    BrowseOpComboBoxCell = [BrowseOpComboBox cell];

    path = @"~/Desktop/files";
    path = [path stringByStandardizingPath];
    const char * dir = [path UTF8String];
    dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:path];
    dirContents = [[dirContents sortedArrayUsingSelector:mad:selector(compare:)] retain];


    - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox {
    return [dirContents count];
    - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index {
    return [dirContents objectAtIndex:index];
    - (NSUInteger)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)string {
    return [dirContents indexOfObject: string];

    - (NSString *) firstGenreMatchingPrefix:(NSString *)prefix {
    NSString *string = nil;
    NSString *lowercasePrefix = [prefix lowercaseString];
    NSEnumerator *stringEnum = [dirContents objectEnumerator];
    while ((string = [stringEnum nextObject])) {
    if ([[string lowercaseString] hasPrefix: lowercasePrefix]) return string;
    return nil;

    - (NSString *)comboBox:(NSComboBox *)aComboBox completedString:(NSString *)inputString {
    NSString *candidate = [self firstGenreMatchingPrefix: inputString];
    return (candidate ? candidate : inputString);

    I have included the Combo Box methods.. And have also obtained the list of files generated in an array, however, I am not able to figure out how to display these in a Combo Box and display the file when the user clicks on any of them.
  4. macrumors newbie

    There was no need of so much code ! It worked with simply this much code !

    path = @"~/Desktop/All/diya/outputs";
    path = [path stringByStandardizingPath];
    dir = [path UTF8String];

    BrowseOpComboBoxCell = [BrowseOpComboBox cell];

    dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:path];

    [BrowseOpComboBox addItemsWithObjectValues:dirContents];

Share This Page