Hi,
I working with view based tables in MacOS X and was having a little diffculty with adding a checkbox to a cell programmatically. More specifically, centering it in the cell that it is being added. Basic question, but I'm stuck.
So, I have a view based table that I'm populating with calendar and reminder data. For rows that are calendar events, I'm populating one of the table cells with an image. For rows that contain a remdiner, I want to populate the same table cell with an NSButton. I've been able to do this, however, the checkbox is stuck with an origin of 0,0 within the cell. I'd like to move it over and up a bit to center it. I've tried changing the orgin after the NSButton is created and that did not work. I've also initialized the NSButton with a rect having the origin I want to have, and that doesn't work. What am I missing?
This is what I currently have in my "- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row" method:
if (typeOfEvent == 1) { //this is a reminder
NSRect checkBoxRect = NSMakeRect(25, 1, 20, 17);
NSButton *toDoCheckBox = [[NSButton alloc] initWithFrame:checkBoxRect];
[toDoCheckBox setButtonType:NSSwitchButton];
[toDoCheckBox setTitle:@""];
return toDoCheckBox;
}
if (typeOfEvent == 0) { //this is a calendar event
NSColor *calendarColor;
calendarColor = [[(EKEvent *)eventOrReminder calendar] color];
NSImage *cellImage = [NSImage imageNamed:@"circle"];
NSImage *coloredImage = [self coloredImage:calendarColor image:cellImage];
[[cellView imageView] setImage:coloredImage];
return cellView;
}
Any suggestions/help is appreciated.
Thanks,
Andy