views:

1022

answers:

1

Hi, I have a NSTableView as a very central part of my Application and want it to integrate more with the rest of it. It has only one column (it's a list) and I draw all Cells (normal NSTextFieldCells) myself.

The first problem is the highlighting. I draw the highlight myself and want to get rid of the blue background. I now fill the whole cell with the original background color to hide the blue background, but this looks bad when dragging the cell around. I tried overriding highlight:withFrame:inView: and highlightColorWithFrame:inView: of NSCell but nothing happened. How can I disable automatic highlighting?

I also want all rows/cells to be deselected when I click somewhere outside my NSTableView. Since the background / highlight of the selected cell turns gray there must be an event for this, but I can't find it. I let my cells expand on a double click and may need to undo this. So getting rid of the gray highlight is not enough.

EDIT: I add a subview to the NSTableView when a cell gets double clicked and then resignFirstResponder of the NSTableView gets called. I tried this:

- (BOOL)resignFirstResponder
{
    if (![[self subviews] containsObject:[[self window] firstResponder]])
    {
     [self deselectAll:self];
     ...
    }

    return YES;
}

Besides that it's not working I would need to implement this method for all objects in the view hierarchy. Is there an other solution to find out when the first responder leaves a certain view hierarchy?

A: 

Overloading -highlight:withFrame:inView: should be correct. How did you do the overload? Does an NSLog() statement indicate that your code is running? You should also look at NSTableView's -highlightSelectionInClipRect:, which may be more convenient for this.

In order to do something (such as unselect the current selection) when the user clicks outside the table view, overload -resignFirstResponder on NSTableView.

Rob Napier
I put ´highlight:withFrame:inView:´ in my NSTextField subclass and it was never called. But overriding ´highlightSelectionInClipRect:´ did the trick, thanks!I thought of ´resignFirstResponder´, but unfortunately I add a subview to the NSTableView so the user can edit the cells content. Is there an other way?
Christian
Are you using the normal field editor for your editing? Does NSTableView's resignFirstResponder not get called when you click outside of it (even with this subview)?
Rob Napier
No, I created my own, more complex view for editing the selected object. `resignFirstResponder` gets called, but it also gets called when the editing view becomes first responder and you can see my attempt to "oversee" this event above.
Christian
If your special editor is a subclass of NSTextField, then you can let NSTableView manage it by overloading NSTableView's -currentEditor. That way, you don't add a new view; you let NSTableView's built-in field editor system work for you.
Rob Napier
Unfortunately it's not. It's a NSView with lot's of things like subviews, PopUpButtons etc. =/
Christian
Sorry, I said NSTextField, I meant NSText (or NSTextView). I'd still take a look at how custom field editors work. You may get a lot of help from working yourself into the system. http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/Tasks/FieldEditor.html
Rob Napier