Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

davbeck

macrumors regular
Original poster
May 16, 2008
104
0
Reno, NV
I have a program, that displays the contents of a csv file (soon to also allow mysql). First I just had it displaying the data, but then I went and added an NSPopUpButtonCell, at the top of each row with the delegate method:
Code:
- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex {
	if(rowIndex == 0) {
		NSPopUpButtonCell *cell = [[[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO] autorelease];
		[cell setEditable:YES];	[cell setBordered:NO];
		[cell addItemsWithTitles:[NSArray arrayWithObjects:@"Data", @"Start X", @"Start Y", @"Start Z", @"End X", @"End Y", @"End Z", @"Ignore", nil]];
		return cell;
	} else {
		NSTextFieldCell *cell = [[[NSTextFieldCell alloc] initTextCell:@""] autorelease];
		[cell setEditable:YES];
		return cell;
	}
}

When I added that, the first column takes up the entire row, no matter what size the row, or the columns, it expands to the entire table, covering the other columns. all the columns are probably the same size (they all have the pop up) but are being covered by the first column.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Don't use this method for setting a custom cell because you're creating a new cell for each row, which is wasteful. The preferred way is to create the cell during awakeFromNib, and assign it to your table column. Something like (untested):
Code:
NSTableColumn *column = [tableView tableColumnWithIdentifier:@"Column1"];
NSPopUpButtonCell *cell = [[[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO] autorelease];
[cell setEditable:YES];
[cell setBordered:NO];
[column setDataCell:cell];

Then implement tableView:willDisplayCell:forTableColumn:row:

Edit: I didn't realize you're using a different cell for different rows, which is strange. If you want to do this, I'd cache the cells in the init method and return them in this method, instead of creating new ones every time.
 

davbeck

macrumors regular
Original poster
May 16, 2008
104
0
Reno, NV
Thanks for the help.
As far as the full width cells go, You have to return nil when given a nil column. Otherwise it will interpret it as being a single cell for the entire row.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.