我正在尝试自定义一个 NSTableView,为此,我实现了以下方法:
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
NSImageView *cellImage = [[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 229, 51)];
cellImage.image = [[NSImage alloc] initByReferencingFile:[[NSBundle mainBundle] pathForImageResource:@"list_cell_secetion_background.png"]];
NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 229, 51)];
NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 10, 150, 30)];
[textField setStringValue:[[_objects objectAtIndex:row] description]];
[textField setBezeled:NO];
[textField setDrawsBackground:NO];
[textField setEditable:NO];
[textField setSelectable:NO];
if(row == selectedCell) [view addSubview:cellImage];
[view addSubview:textField];
return view;
}
所以它工作正常,直到您单击标签所在的位置。然后它不会发生任何事情。我想点击单元格中的任何地方,正确选择。