2013-08-21 231 views
0

我有點卡住了,似乎無法從蘋果文檔中解決這個問題。NSTableView隱藏按鈕

我在NSTable列中包含兩個按鈕,包含在NSTableCellView中。

我想在代碼中隱藏該按鈕取決於該行中對象的值。

獲取值是好的,但我不能解決如何針對特定的按鈕,我不能將它綁定到一個插座,因爲它是在一個表內。我已經嘗試了下面的代碼,但這只是隱藏了整個NSTableCellView而不是特定的按鈕,我也嘗試將標識符更改爲按鈕,但似乎也這樣做。

if(selectedTweet.imageURL){ 

     NSButton *imageButton = [tableView makeViewWithIdentifier:@"secondButtons" owner:self]; 
     [imageButton setHidden:NO]; 
     return imageButton; 

    } else { 

     NSButton *imageButton = [tableView makeViewWithIdentifier:@"secondButtons" owner:self]; 
     [imageButton setHidden:YES]; 
     return imageButton; 

    } 

這顯然比我做它更簡單?非常感謝。

感謝

加雷思

+0

從你的代碼我看到你正試圖創建一個NSTableCellView的按鈕可見/隱藏取決於條件。你試着在IB上有兩個不同的預定義的NSTableCellView,如「secondButtonsWithButton」和「secondButtonsWithoutButton」,並調用每個必要時 ? – CoderPug

回答

0

如果使用CocoaBindings來填充表,你可以將按鈕的「隱藏」屬性綁定到Table Cell View/objectValue.imageURL並使用NSIsNil值轉換。根本不需要代碼。

如果您使用的是老式的數據源,事情會變得更加複雜。在這種情況下,你可以在你的對象中有一個imageButton屬性,並將其設置在NSTableViewDelegate的方法- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row中。

+0

神牛糞這麼簡單,謝謝你,也解決了我遇到的其他一些問題。傳說! –