2013-05-31 23 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不起作用,但选择插座呢? –