2013-05-31 22 views
0

我有兩個基於單元格的表格(項目和類別)。我試圖得到正確的行索引,因此我可以使用它們的數組。使用兩個表格 - 如何獲得正確的行

到目前爲止我的代碼是這樣的:我使用了錯誤的方法,或者是我

currentCategory is Cat One 
currentCategory is Cat Three 
currentCategory is Cat One 
currentCategory is Cat Three 
currentCategory is Cat One 
currentCategory is Cat Three 
currentCategory is Cat Two 
currentCategory is Cat One 
currentCategory is Cat Three 
... 

- (id) tableView:(NSTableView *)tableView 
objectValueForTableColumn:(NSTableColumn *)tableColumn 
     row:(NSInteger)row { 
    //NSLog(@"%s", __FUNCTION__); 

    if (tableView.tag == 0) { 
     currentItem = [itemMutableArray objectAtIndex:row]; 
     NSString *itemTitle1 = [currentItem valueForKey:@"title"]; 
     return itemTitle1; 
    } else { 
     currentCategory = [categoryMutableArray objectAtIndex:row]; 
     NSString *catName = [currentCategory valueForKey:@"name"]; 
     NSLog (@"currentCategory is %@", catName); 
     return catName; 
    } 
} 

但每個表,這將返回類似?謝謝。

+0

什麼問題了嗎? – Undo

+0

我希望能夠識別每個表的特定行。 –

+0

我們需要知道數組的內容以及日誌*應該說的內容。 – Undo

回答

1

如果您在同一個控制器中有多個表格,那麼爲他們提供插口是個好主意。

然後你可以使用如:

- (id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { 

    if(tableView==myFirstTableViewOutlet){ 
     ..... 
    } 
    else if(tableView==mySecondTableViewOutlet){ 
     ..... 
    } 
} 
+0

謝謝Anoop,我會試試這個.. –

+0

這樣做..非常感謝 –

+0

任何想法爲什麼tableview.tag不起作用,但選擇插座呢? –