NSComboBox source data the files ina diretory

boyfarrell

Registered
Hi everyone,

I want to provide the source data to NSComboBox to be the names of file in a directory. When the item in the combo box is selected I want it to read in the data (It will be 2 column data file tab delimited).

Is this easy?

Is there a better way i.e. not using NSComboBox?

I'm new to cocoa but have done the currency converter application on Apple's site.

The first think I should learn is cocoa's input output commands for reading in data files? What are these called.
 
Do you mean NSPopUpButton? NSComboBox's aren't used for this type of stuff usually. You'd probably want an NSPopUpButton to store the files.

Anyways, assuming you do want a pop up button, here's a way to fill it with files from a directory:
Code:
- (void)updateFiles
{
	NSString *dir = [@"~/Desktop" stringByExpandingTildeInPath];
	NSArray *files = [[NSFileManager defaultManager] directoryContentsAtPath:dir];
	int i;
	
	[popUpButton removeAllItems];
	for (i=0; i<[files count]; i++)
	{
		[popUpButton addItemWithTitle:[files objectAtIndex:i]];
	}
}
If you do really want to use an NSComboBox, you would use addItemWithObjectValue: instead.
 
I will give that I go thanks for the code.

When your starting out it's not immedately obvious what things are used for what processes, I never though about using NSPopUpBotton, I just grabbed the first thing that looked appropirate!

Cheers.
 
Back
Top