Here is another posting of my tableview application. I previously posted code that would print text "jimmy" in custom cells I made, in a tableview. I had a popupbutton that would changed the text from column to column, depending on which numbered column was selected. This worked OK. What I really want, though, is to select a number from the popupbutton and have it print the text in individual cells, not just the columns. Below is the current code. The custom cell works fine.
custom cells--
then the app controller ...
This runs without errors but says "Stub implementation of -setAction by NSCell does nothing". Am I incorrectly setting up the target/action in the nib file? Any help is appreciated. Thanks.
Adam
custom cells--
Code:
#import "MyCell.h"
@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
then the app controller ...
Code:
#import "AppController.h"
#import "MyCell.h"
@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];
[myCell setAction:@selector(asmbutton1:)];
[myCell setTarget:self];
}
-(int)numberOfRowsInTableView:(NSTableView *)tv
{
return [data count];
}
-(id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
return [data objectAtIndex:row];
}
-(IBAction)asmbutton1:(id)sender;
{
NSString*buttonString=[(NSPopUpButton*)sender titleOfSelectedItem];
NSString*mySecondString=@"jimmy";
NSString*myThirdString=@"";
NSInteger*myRow;
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"];
NSTableColumn*column3=[tv tableColumnWithIdentifier:@"columnThree"];
myRow=[tv selectedRow];
someCell=[[[MyCell alloc]init]autorelease];
someCell=[super dataCellForRow:myRow];
if ([buttonString isEqualToString:@"1"]){
[column setDataCell:mySecondCell];
[column2 setDataCell:myThirdCell];
if (myRow==2) [someCell setObjectValue:myThirdCell];
}
if ([buttonString isEqualToString:@"2"]){
[column setDataCell:myThirdCell];
[column2 setDataCell:mySecondCell];
if (myRow==2) [someCell setObjectValue:myThirdCell];
}
if ([buttonString isEqualToString:@"3"]){
[column setDataCell:mySecondCell];
[column2 setDataCell:myThirdCell];
if (myRow==1) [someCell setObjectValue:myThirdCell];
}
if ([buttonString isEqualToString:@"4"]){
[column setDataCell:myThirdCell];
[column2 setDataCell:mySecondCell];
if (myRow==1) [someCell setObjectValue:myThirdCell];}
[tv reloadData];
}
@end
This runs without errors but says "Stub implementation of -setAction by NSCell does nothing". Am I incorrectly setting up the target/action in the nib file? Any help is appreciated. Thanks.
Adam