2012-06-23 32 views
0

我有一個包含分割視圖的窗口。其中一個「分割」包含大綱視圖。我有一個窗口控制器(窗口的XIB的文件所有者)。窗口控制器是大綱視圖的委託和數據源。大綱視圖中的鼠標事件

當我在窗口控制器中調用-(void)mouseDown:(NSEvent *)e方法時,只有工具欄響應該方法 - 大綱視圖沒有。

如何獲取鼠標事件大綱視圖的mouseDown?

回答

1

獲得大綱視圖的鼠標事件:

  1. 子類中的大綱視圖。
    • 在Interface Builder(IB)>庫面板>類標籤中選擇NSOutlineView
    • 右鍵單擊NSOutlineView並選擇「新子......」
    • 完成以下彈出窗口中選擇「生成源文件」和FILS添加到您的項目
    • 選擇NSOutlineView
    • 在督察面板>身份標籤>類標識>類選擇新的類
  2. 默認地將Impl ement your mouse event method

    • 在Xcode>您的大綱視圖的新子類>實現(。

      (void)mouseDown:(NSEvent *)theEvent { 
          /* CODE YOU WANT EXECUTED WHEN MOUSE IS CLICKED */ 
          NSLog(@"Mouse down occurred"); 
          // call this to get the usual behaviour of your outline 
          // view in addition to your custom code 
          [super mouseDown:theEvent]; 
      } 
      

這可能是有用的知道,一個可以用[NSEvent modifierFlags]獲得鼠標事件。這不僅適用於大綱視圖,還適用於整個應用程序的視圖。例如,在窗口控制器(在問題中提到),我可以包含如下代碼:

if ([NSEvent modifierFlags] == NSAlternateKeyMask) { // if the option key is being pressed 
      /*SOME CODE*/ 
}