gpt4 book ai didi

cocoa - 使用两个表 - 如何获取正确的行

转载 作者:行者123 更新时间:2023-12-03 17:53:57 25 4
gpt4 key购买 nike

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

到目前为止我的代码是这样的:

- (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
...

是我使用的方法不对还是什么?谢谢。

最佳答案

如果同一个 Controller 中有多个表,最好为它们提供 socket 。

然后你可以使用:

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

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

关于cocoa - 使用两个表 - 如何获取正确的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16861023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com