Cocoa 使用两个表-如何获得正确的行

Cocoa 使用两个表-如何获得正确的行,cocoa,osx-mountain-lion,Cocoa,Osx Mountain Lion,我有两个基于单元格的表视图(项目和类别)。我正在尝试为每个数组获取正确的行索引,以便使用它们的数组 到目前为止,我的代码是: - (id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { //NSLog(@"%s", __FUNCTION__); if (tableView.tag ==

我有两个基于单元格的表视图(项目和类别)。我正在尝试为每个数组获取正确的行索引,以便使用它们的数组

到目前为止,我的代码是:

- (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;
    }
}
但对于每个表,它都会返回如下结果:

 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 {

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

我希望能够识别每个表的特定行。我们需要知道数组的内容以及日志应该显示什么。谢谢,我将尝试这个..成功。。很多人都不知道为什么tableview.tag不起作用,但选择插座却起作用?@davidelmonte:坦率地说,我从来没有尝试过使用标签。我想标签应该有用。再次检查是否已为“表格不滚动”视图设置标记,并确认两个表格具有不同的标记。