【问题标题】:Selecting a NSCell with 1 click, without selecting the row first?一键选择NSCell,而不先选择行?
【发布时间】:2013-10-18 19:41:31
【问题描述】:

当我在 NSTableView 中选择一个 NSTextFieldCell 时,行为会因是否选择行而有所不同。

  • 如果选择了行,则立即选择单元格,并且光标在文本字段内闪烁

  • 如果没有选中行,点击后唯一的变化就是选中了行,但是单元格没有进入编辑模式。

我希望在单击 1 次后让单元格在这两种情况下都进入编辑模式。

【问题讨论】:

    标签: objective-c cocoa


    【解决方案1】:

    在下面实现这个方法,它会编辑你的单元格:-

    - (void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag
    

    【讨论】:

      【解决方案2】:

      我认为您想要的是一键编辑您的单元格。为此,您需要子类化您的 tableview 并将其 mousedown: 事件捕获为

      - (void)mouseDown:(NSEvent *)theEvent
        {
      
             NSPoint globalLocation = [theEvent locationInWindow];
             NSPoint localLocation = [self convertPoint:globalLocation fromView:nil];
             NSInteger clickedRow = [self rowAtPoint:localLocation];
             NSInteger clickedCol = [self columnAtPoint:localLocation];
      
             [super mouseDown:theEvent];
      
             [self editColumn:clickedCol row:clickedRow withEvent:theEvent select:YES];
      
        }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-20
        • 1970-01-01
        • 2020-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多