Search code examples
objective-ccocoacellnstableviewnstextfield

Click under NSTextField


I'm trying to customize a NSTableView, in order to do that, I've implemented the following method:

-(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;
}

So it works fine, until you click where the label is. Then it doesn't occurs anything. I would like to click everywhere in the cell, getting selected correctly.


Solution

  • Disabling the textfield will allow the user to click beneath the textfield.

        [textField setEnabled:NO];