2013-03-02 95 views
4

我需要檢測NSTableView的標題上的雙擊。檢測NSTableview標題上的雙擊

我發現,雙擊觸發以下,但我不能就檢測已被點擊哪一列:

[table setTarget:self]; 
[table setDoubleAction:@selector(myDoubleClickInList:)]; 

和內部myDoubleClickInList:方法我用

[table clickedRow] == -1 

得到頭。

但我無法從[table clickedColumn] 獲得列標識符是否可能?

回答

2

假設你有訪問稱爲table那麼下面就讓你得到的列標識符的一個實例變量或屬性,

NSInteger column = [table clickedColumn]; 
NSRange columnRange = NSMakeRange(0, [table numberOfColumns]); 
if (NSLocationInRange(column, columnRange){ 
    NSTableColumn *tableColumn = [[table tableColumns] objectAtIndex:column]; 
    NSString *identifier = [tableColumn identifier]; 
    // Now do something with the column identifier... 

} else { 
    // The click was not in a column, do something else... 
} 
+0

非常感謝! :) – sharkyenergy 2013-03-03 12:04:43

-2

如果我不得不這樣做,我會創建一個UIview子類UITapGestureRecognizer(雙擊 - >選擇器)添加在視圖頂部,並在- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section返回該自定義視圖。儘管我現在不能提供任何代碼,但我仍希望這會有所幫助。

+0

或者,如果默認表剖面圖是對你不夠好,爲什麼不會你將該手勢識別器添加到'viewForHeaderInSection:'中的視圖? – user1244109 2013-03-02 14:27:26

+0

ehm,抱歉忘了提及我在osx上不是ios ...無論如何,這項工作還會繼續嗎? – sharkyenergy 2013-03-02 16:24:32

+1

顯然整個問題都沒有被讀取。不,那個答案在OS X上不起作用。 – 2013-03-06 21:20:40