PDA

View Full Version : NSComboBox Help




Khanjan
Jul 2, 2009, 02:10 PM
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



kainjow
Jul 2, 2009, 07:34 PM
Post your code. Hard to tell what's wrong without it. Also double-check your IB connections.

Khanjan
Jul 6, 2009, 11:01 AM
(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:@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.

Khanjan
Jul 7, 2009, 01:12 PM
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];