1

我一直在尝试编辑和更新源列表 NSOutlineView 中的项目,但没有成功,我使用的不是树控制器,而是数据源和委托。

我的理解是,outlineView:setObjectValue:forTableColumn:byItem 数据源方法适用于基于单元格的大纲视图,并且不会因基于视图而被调用。

NSTableView 有一个类似的数据源方法 tableView:setObjectValue:forTableColumn:row,但是这次文档声明它是用于基于单元格的表格,并且“相反,目标/操作用于视图单元格中的每个项目。”</p>

所以,我不太确定该怎么做,我尝试了下面的文本字段委托方法;

    - (void)controlTextDidBeginEditing:(NSNotification *)aNotification
{
    selectedRowList = [[self outlineView] selectedRow];
}

- (void)controlTextDidEndEditing:(NSNotification *)aNotification
{

    NSManagedObject *selectedGoal = [[self outlineView] itemAtRow:selectedRowList];

    NSTableCellView *viewCell = [[self outlineView] makeViewWithIdentifier:@"DataCell" owner:self];

    [selectedGoal setValue:[[viewCell textField] stringValue] forKey:@"goalName"];

    [self updateOutlineView];
}

我可以更改文本字段的值,但是我似乎无法从视图中获取此值。我认为问题是该行不再被选中一次 - (void)controlTextDidEndEditing:(NSNotification *)aNotification 被执行。

有人可以为我指出如何最好地处理更新 NSOutlineView 项目的正确方向吗?

谢谢

4

1 回答 1

2

我在基于 NSOutlineView 的视图中遇到了同样的问题,我曾经controlTextDidChange:获取更新:

- (void)controlTextDidChange:(NSNotification *)notification {
    NSTextField *textField = [notification object];
    NSTableRowView *parentRow = (NSTableRowView*)[[textField superview] superview];
    NSInteger row = [self.outlineView rowForView:parentRow];

    //..
}
于 2014-05-11T18:08:05.800 回答