【发布时间】:2011-04-01 04:52:38
【问题描述】:
如何在 NSTableView 中设置一列复选框?到目前为止,这就是我所做的,但它只是将 int 1 放在列中,而不是复选框:
-(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row {
if ([[tableColumn identifier] isEqualToString:@"Enable"]) {
NSButtonCell *cell=[[[NSButtonCell alloc] init] autorelease];
[cell setAllowsMixedState:YES];
[cell setButtonType:NSSwitchButton];
NSCell *aCell = [tableColumn dataCellForRow:row];
[aCell setObjectValue:cell];
return [NSNumber numberWithInt:1];
}
return [[data objectAtIndex:row+1] objectAtIndex:[[data objectAtIndex:0] indexOfObject:[tableColumn identifier]]];
}
【问题讨论】:
-
您应该实现
NSTableViewDelegate方法tableView:willDisplayCell:forTableColumn:row:或tableView:dataCellForTableColumn:row:,而不是在objectValueForTableColumn:...中获取单元格(我不清楚您要做什么)。
标签: objective-c cocoa nstableview nsbutton