Selection and Key Features of NSTableView

I have NSTableView as a very central part of my application and want it to integrate with the rest of it. It has only one column (this is a list), and I draw all the cells myself (regular NSTextFieldCells).

The first problem is isolation. I draw the selection myself and want to get rid of the blue background. Now I fill the entire cell with the original background color to hide the blue background, but this does not look good when dragging the cell. I tried to override highlight:withFrame:inView:and highlightColorWithFrame:inView:NSCell, but nothing happened. How to disable automatic selection?

I also want all rows / cells to be undone when I click somewhere outside my NSTableView. Since the background / selection of the selected cell becomes gray, there must be an event for this, but I can not find it. I allow my cells to expand with a double click and may need to undo this. Therefore, getting rid of gray discharge is not enough.

EDIT: I add subview to NSTableView when the cell gets a double click and then resignFirstResponderNSTableView is called. I tried this:

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

    return YES;
}

In addition, it does not work, I will need to implement this method for all objects in the view hierarchy. Is there any other solution to find out when the first responder leaves a certain hierarchy of views?

+3
3

( NSOutlineView, ): , (, ), , . , .

NSOutlineView :

@implementation ClickOutlineView

- (void)mouseDown:(NSEvent *)theEvent
{
    NSPoint pointInWindow = [theEvent locationInWindow];
    NSPoint pointInOutlineView = [self convertPoint:pointInWindow toView:nil];

    int rowIndex = [self rowAtPoint:pointInOutlineView];

    if ([theEvent clickCount] == 1 && rowIndex == -1) {
        [self deselectAll:nil];
    }
    else {
        [super mouseDown:theEvent];
    }
}

@end
+2

, , , , Google ( ).

, "" "" Xcode 4.

SO .

+1

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

To do something (for example, deselect the current selection) when the user clicks outside the table view, reload -resignFirstResponderinto NSTableView.

0
source

Source: https://habr.com/ru/post/1715418/


All Articles