我有两个基于单元格的表格视图(项目和类别)。我正在尝试为每个获取正确的行索引,以便可以使用它们的数组。
到目前为止,我的代码是这样的:
- (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
...
我使用了错误的方法,还是什么?谢谢。