Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在“表视图”单元格中使用修改键进行鼠标跟踪_Objective C_Cocoa_Nstableview_Nscell - Fatal编程技术网

Objective c 在“表视图”单元格中使用修改键进行鼠标跟踪

Objective c 在“表视图”单元格中使用修改键进行鼠标跟踪,objective-c,cocoa,nstableview,nscell,Objective C,Cocoa,Nstableview,Nscell,我在基于单元格的NSTableView的列中有一个NSTextFieldCell。这个单元格应该处理点击。当未按下任何修改键时,此功能正常工作。如果按住shift或command键,则表视图将吞下mouseDown事件,以尝试处理行选择 有没有办法在NSTableView中完全禁用行选择 有没有办法让NSTableView通过所有事件 My cell子类派生自TableViewLinks示例代码中的LinkTextFieldCell。它执行: - (BOOL)trackMouse:(NSEven

我在基于单元格的NSTableView的列中有一个NSTextFieldCell。这个单元格应该处理点击。当未按下任何修改键时,此功能正常工作。如果按住shift或command键,则表视图将吞下mouseDown事件,以尝试处理行选择

有没有办法在NSTableView中完全禁用行选择

有没有办法让NSTableView通过所有事件

My cell子类派生自TableViewLinks示例代码中的LinkTextFieldCell。它执行:

- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)rowIndex
{
    return NO;
}

- (BOOL)tableView:(NSTableView *)tableView shouldTrackCell:(NSCell *)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    return YES;
}
由于我不需要行选择,我的表视图委托实现:

- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)rowIndex
{
    return NO;
}

- (BOOL)tableView:(NSTableView *)tableView shouldTrackCell:(NSCell *)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    return YES;
}
我的委托方法是从-[NSTableView mouseDown:]调用的。当未按下任何修改键时,将调用鼠标跟踪代码


有没有比将NSTableView子类化为override-[NSTableView mouseDown:]更好的方法来解决这个问题?

我已经实现了一个覆盖mouseDown:。我真的不喜欢它。但它是有效的。仍然希望有更好的想法

- (void)mouseDown:(NSEvent *)theEvent
{
    if (! [self handleMouseDown:theEvent]) {
        [super mouseDown:theEvent];
    }
}

- (BOOL)handleMouseDown:(NSEvent *)theEvent
{
    NSInteger                   clickCount                  = [theEvent clickCount];

    if (clickCount != 1) {
        return NO;
    }

    NSPoint                     locationInWindow            = [theEvent locationInWindow];
    NSPoint                     locationInView              = [self convertPoint:locationInWindow fromView:nil];
    NSInteger                   clickedRow                  = [self rowAtPoint:locationInView];
    NSInteger                   clickedColumn               = [self columnAtPoint:locationInView];

    if ((clickedRow < 0) || (clickedColumn < 0)) {
        return NO;
    }

    if ((clickedRow >= [self numberOfRows]) || (clickedColumn >= [self numberOfColumns])) {
        return NO;
    }

    NSArray                     *tableColumns               = [self tableColumns];

    NSTableColumn               *tableColumn                = [tableColumns objectAtIndex:clickedColumn];
    NSCell                      *cell                       = [tableColumn dataCellForRow:clickedRow];

    id <NSTableViewDelegate>    delegate                    = [self delegate];
    BOOL                        shouldTrackCell             = NO;

    if ([delegate respondsToSelector:@selector(tableView:shouldTrackCell:forTableColumn:row:)]) {
        shouldTrackCell = [delegate tableView:self shouldTrackCell:cell forTableColumn:tableColumn row:clickedRow];
    }

    if (! shouldTrackCell) {
        return NO;
    }

    BOOL                        prefersTrackingUntilMouseUp = [[cell class] prefersTrackingUntilMouseUp];
    NSRect                      cellFrame                   = [self frameOfCellAtColumn:clickedColumn row:clickedRow];

    return [cell trackMouse:theEvent inRect:cellFrame ofView:self untilMouseUp:prefersTrackingUntilMouseUp];
}
-(void)鼠标向下移动:(n事件*)事件
{
如果(![self HandleMouse Down:theEvent]){
[超级鼠标镇:theEvent];
}
}
-(BOOL)把手放下:(n事件*)事件
{
NSInteger clickCount=[theEvent clickCount];
如果(单击计数!=1){
返回否;
}
NSPoint Location InWindow=[theEvent Location InWindow];
NSPoint locationInView=[self-convertPoint:locationInWindow fromView:nil];
NSInteger clickedRow=[自排点:位置查看];
NSInteger clicked column=[self columnAtPoint:locationInView];
如果((单击箭头<0)| |(单击列<0)){
返回否;
}
如果((单击箭头>=[self numberOfRows])| |(单击列>=[self numberOfColumns])){
返回否;
}
NSArray*tableColumns=[self-tableColumns];
NSTableColumn*tableColumn=[tableColumns objectAtIndex:clickedColumn];
NSCell*cell=[tableColumn dataCellForRow:clickedRow];
id委托=[自委托];
BOOL shouldTrackCell=否;
if([delegate respondsToSelector:@selector(tableView:shouldTrackCell:forTableColumn:row:])){
shouldTrackCell=[委托表视图:self shouldTrackCell:单元格forTableColumn:表列行:clickedRow];
}
如果(!shouldTrackCell){
返回否;
}
BOOL preferstrackuntilmouseup=[[cell class]preferstrackuntilmouseup];
NSRect cellFrame=[self-frameOfCellAtColumn:clickedColumn行:clickedRow];
return[cell trackMouse:theEvent-inRect:cell-frame-of-view:self-untillmouseup:preferstrackinguntillmouseup];
}

您能让表REQUESESFIRSTREPSONDER吗?这就是我所能想到的,但我不确定它是否会破坏其他东西。出于某种原因,我已经接受了FirstResponder返回号。没有区别。