Hi, I am using NSTableView, it contains 2 columns A and B
A contains data B contains buttons
I want when the user clicks on any button inside the table view, then its image should be changed.
How to add custom button inside tableview cell:
NSButtonCell *buttonCell = [[[NSButtonCell alloc] init] autorelease];
[buttonCell setBordered:NO];
[buttonCell setImagePosition:NSImageOnly];
[buttonCell setButtonType:NSMomentaryChangeButton];
[buttonCell setImage:[NSImage imageNamed:@"uncheck.png"]];
[buttonCell setSelectable:TRUE];
[buttonCell setTarget:self];
[buttonCell setAction:@selector(deleteSongContent:)];
[[myTable tableColumnWithIdentifier:@"EditIdentifier"] setDataCell:buttonCell];
When I click the button, the selection method starts, but I don’t understand how to change the image of the button cell.
Any suggestions please !!!!!!!
Edit:
When I click the button, the method is called and how it works:
-(void)selectButtonsForDeletion:(NSTableView *)tableView
{
NSEvent *currentEvent = [[tableView window] currentEvent];
int columnIndex = [tableView columnAtPoint:
[tableView convertPoint:
[currentEvent locationInWindow] fromView:nil]];
NSTableColumn *column = [[tableView tableColumns]objectAtIndex:columnIndex];
NSButtonCell *aCell = [[tableView tableColumnWithIdentifier:
[column identifier]]
dataCellForRow:[tableView selectedRow]];
NSInteger index = [[aCell title] intValue];
if(![selectedIndexesArray containsObject:[NSNumber numberWithInt:index]])
{
[aCell setImage:[NSImage imageNamed:@"check.png"]];
[selectedIndexesArray addObject:[NSNumber numberWithInt:index]];
}
else
{
[aCell setImage:[NSImage imageNamed:@"uncheck.png"]];
[selectedIndexesArray removeObjectAtIndex:[selectedIndexesArray indexOfObject:[NSNumber numberWithInt:index]]];
}
}
Swati source
share