NSComboBox Help

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

  1. macrumors newbie

    Joined:
    Jun 25, 2009
    #1
    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,
    Khanjan
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Post your code. Hard to tell what's wrong without it. Also double-check your IB connections.
     
  3. thread starter macrumors newbie

    Joined:
    Jun 25, 2009
    #3
    (IBAction)rundiya: (id)sender
    {

    BrowseOpComboBoxCell = [BrowseOpComboBox cell];

    path = @"~/Desktop/files";
    path = [path stringByStandardizingPath];
    const char * dir = [path UTF8String];
    chdir(dir);
    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. thread starter macrumors newbie

    Joined:
    Jun 25, 2009
    #4
    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];
    chdir(dir);

    BrowseOpComboBoxCell = [BrowseOpComboBox cell];


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

    [BrowseOpComboBox addItemsWithObjectValues:dirContents];
     

Share This Page