展开项目时 NSOutlineView 行索引发生变化
假设我有一个 NSTableView(例如,a
)和一个 NSOutlineView(例如,b
)。
在 a
的数据源中,我试图获取 b
的所有选定项目的父项目。在行号中。 a
的 rowIndex
我想要选择 b
的第 rowIndex
项和 我想将此字符串连接到该项目的父项的名称。例如,a
:
- 1 和 1.1
- 2
和 b
:
- 1
- 1.1(已选择)
- 2(选定)
- 3
这是 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
of 一个。
NSUInteger index = [[outlineView selectedRowIndexes] firstIndex];
for (NSUInteger i = 0, target = rowIndex; i < target; i++)
index = [[outlineView selectedRowIndexes] indexGreaterThanIndex:index];
NSLog(@"%@", [outlineView [outlineView itemAtRow:index]]);
if([outlineView parentForItem:[outlineView itemAtRow:index]] != NULL) {
return [NSString stringWithFormat:@"%@ %@", [outlineView parentForItem:[outlineView itemAtRow:index]], [outlineView itemAtRow:index]];
} else {
return [outlineView itemAtRow:index];
}
return NULL;
问题是,当我展开项目时 [outlineView ParentForItem:[outlineView itemAtRow:index]]
始终返回最后一个展开的项目。
我正在尝试列出所选项目及其父母。当我展开某个项目时,所有项目都将其父项更改为最后展开的项目
。
我做错了什么吗?
先感谢您。
Say I have a NSTableView (for example, a
) and a NSOutlineView (for example, b
).
In the datasource of a
I'm trying to get the parent item of all the selected items of b
. In the row no. rowIndex
of a
I would like to have the rowIndex
th selected item of b
and I would like to concatenate this string to the name of the parent of this item. For example, a
:
- 1 and 1.1
- 2
And b
:
- 1
- 1.1 (selected)
- 2 (selected)
- 3
This is - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
of a
.
NSUInteger index = [[outlineView selectedRowIndexes] firstIndex];
for (NSUInteger i = 0, target = rowIndex; i < target; i++)
index = [[outlineView selectedRowIndexes] indexGreaterThanIndex:index];
NSLog(@"%@", [outlineView [outlineView itemAtRow:index]]);
if([outlineView parentForItem:[outlineView itemAtRow:index]] != NULL) {
return [NSString stringWithFormat:@"%@ %@", [outlineView parentForItem:[outlineView itemAtRow:index]], [outlineView itemAtRow:index]];
} else {
return [outlineView itemAtRow:index];
}
return NULL;
The problem is that when I expand an item [outlineView parentForItem:[outlineView itemAtRow:index]]
returns always the last expanded item.
I am trying to have a list of selected items and their parents. When I expand an item, all items change their parent to last expanded item
.
Am I doing something wrong?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您发现的那样,您不能使用简单的整数来表示嵌套数据集中的索引。相反,您需要使用 NSIndexPath< /a>.正如文档所说:
You can't use a simple integer to represent an index in a nested set of data, as you found out. Instead you need to use NSIndexPath. As the docs put it: