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

medasmx

macrumors member
Original poster
Nov 9, 2008
89
0
This is the newest version of my custom cell tableview (last post titled "custom cells in tableview") program. You can refer to the earlier post for a version that would print text in each column. What I want to do is put text in individual cells. The code below runs without errors, but when the popupbutton is changed from "1" (cell 0,0) to "4" (cell 1,1), nothing happens. In my earlier version, the text appeared appropriately, but not in individual cells, only in each column.

custom cell code ...
Code:
@implementation MyCell

-(void)prepareAttributes
{
	attributes=[[NSMutableDictionary alloc]init];
	[attributes setObject:[NSFont fontWithName:@"Helvetica" size:20] forKey:NSFontAttributeName];
	[attributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
}

- (id)initWithFrame:(NSRect)frameRect {
    self = [super initWithFrame:frameRect];

    if (!self) return nil;
	[self prepareAttributes];
	string=@"Jimmy";
    return self;
}

-(void)dealloc
{
	[string release];
	[super dealloc];
}

-(NSString*)string
{
	return string;
}

-(void)setString:(NSString*)c
{
	c=[c copy];
	[string release];
	string=c;
}

-(void)drawStringCenteredIn:(NSRect)cellFrame
{
	NSPoint textPoint;
		
	textPoint.x = cellFrame.origin.x + 5;
	textPoint.y = cellFrame.origin.y;
	
	[string drawAtPoint:textPoint withAttributes:attributes];
}


-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
{
	[[NSColor grayColor]set];
	NSRectFill(NSInsetRect(cellFrame,4,4));

	[self drawStringCenteredIn:cellFrame];
}

@end

app controller code...

Code:
@implementation AppController

-(void)awakeFromNib
{
	data=[[NSArray alloc]initWithObjects:@"1",@"2",nil];
	myCell=[[[MyCell alloc]init]autorelease];
	NSTableColumn*column=[tv tableColumnWithIdentifier:@"columnOne"];
	[column setDataCell:myCell];
	NSTableColumn*column2=[tv tableColumnWithIdentifier:@"columnTwo"];
	[column2 setDataCell:myCell];
	[tv setRowHeight:100];
}

-(int)numberOfRowsInTableView:(NSTableView *)tv
{
	return [data count];
}

-(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row 
{
	return [data objectAtIndex:row];
}

-(id)dataCellForRow:(int)row
{
	someCell=[[[MyCell alloc]init]autorelease];
	someCell=[super dataCellForRow:row];
	
	NSString*mySecondString=@"jimmy";
	NSString*myThirdString=@"";
	mySecondCell=[[[MyCell alloc]init]autorelease];
	myThirdCell=[[[MyCell alloc]init]autorelease];
	[mySecondCell setString:mySecondString];
	[myThirdCell setString:myThirdString];
	
	NSTableColumn*column=[tv tableColumnWithIdentifier:@"columnOne"];
	NSTableColumn*column2=[tv tableColumnWithIdentifier:@"columnTwo"];
	
	if ([(NSPopUpButton*)asmbutton1 titleOfSelectedItem]==1){
		[column setDataCell:mySecondCell];
		[column2 setDataCell:myThirdCell];
		if (row==2) [someCell setObjectValue:myThirdCell];
	}
	
	if ([(NSPopUpButton*)asmbutton1 titleOfSelectedItem]==2){
		[column setDataCell:myThirdCell];
		[column2 setDataCell:mySecondCell];
		if (row==2) [someCell setObjectValue:myThirdCell];
	}
	
	if ([(NSPopUpButton*)asmbutton1 titleOfSelectedItem]==3){
		[column setDataCell:mySecondCell];
		[column2 setDataCell:myThirdCell];
		if (row==1) [someCell setObjectValue:myThirdCell];
	}
	
	if ([(NSPopUpButton*)asmbutton1 titleOfSelectedItem]==4){
		[column setDataCell:myThirdCell];
		[column2 setDataCell:mySecondCell];
		if (row==1) [someCell setObjectValue:myThirdCell];
	}
	
	return someCell;
}

@end

Any help is appreciated. Adam
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.