【问题标题】:Updating NSOutlineView items更新 NSOutlineView 项目
【发布时间】:2013-05-23 21:49:38
【问题描述】:

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

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

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

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

    - (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 项目的正确方向吗?

谢谢

【问题讨论】:

    标签: cocoa nstableview nsoutlineview


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多