【问题标题】:What would prevent an editable NSTableColumn from being editable on double-click?什么会阻止可编辑的 NSTableColumn 在双击时可编辑?
【发布时间】:2013-11-19 14:15:37
【问题描述】:

我有一个NSTableView,只有一列。此列在 Interface Builder 中选中了“可编辑”,但双击表格视图中的单元格没有任何作用。我已经确认(在-tableView:viewForTableColumn:row: 通过检查[tableColumn isEditable])表列设置了可编辑标志。如果isEditable == YES 会阻止该列被编辑?

有人建议我包含我的数据源和委托代码。 dataArray 是一个存储NSManagedObject 子类对象的属性。 listPopupButton 在可以显示不同实体的NSTableView 中选择要查看的实体,所有这些实体都只有一个名称属性(如返回这些数组的nameOnlyItems 方法所示)。

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
  return [[self dataArray] count];
}

- (NSView *)tableView:(NSTableView *)tableView
   viewForTableColumn:(NSTableColumn *)tableColumn
                  row:(NSInteger)row {
  NSTableCellView *cellView;
  NSNumber *index = [NSNumber numberWithInteger:[[self listPopupButton] indexOfSelectedItem]];

  if ([[self nameOnlyItems] containsObject:index]) {
    CVCAbstractEntity *entity = [[self dataArray] objectAtIndex:row];
    NSString *name = [entity name];
    cellView = [tableView makeViewWithIdentifier:@"nameOnly" owner:self];
    [[cellView textField] setStringValue:name];

  } else if ([index integerValue] == CVCListPopUpIndexPublishers) {
    CVCPublisher *publisher = [[self dataArray] objectAtIndex:row];
    NSString *identifier = [tableColumn identifier];
    NSString *content;

    content = [[publisher valueForKeyPath:identifier] description];
    if ([identifier containsString:@"year"] && [content isEqualToString:@"0"]) {
      content = @"";
    }

    cellView = [tableView makeViewWithIdentifier:identifier owner:self];
    [[cellView textField] setStringValue:content ? content : @""];

  } else if ([index integerValue] == CVCListPopUpIndexSeries) {
    CVCSeries *series = [[self dataArray] objectAtIndex:row];
    NSString *identifier = [tableColumn identifier];
    NSString *content;

    content = [[series valueForKeyPath:identifier] description];
    if ([identifier containsString:@"year"] && [content isEqualToString:@"0"]) {
      content = @"";
    }

    cellView = [tableView makeViewWithIdentifier:identifier owner:self];
    [[cellView textField] setStringValue:content ? content : @""];
  }

  return cellView;
}

- (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors {
  NSMutableArray *mutableDataArray = [[self dataArray] mutableCopy];
  [mutableDataArray sortUsingDescriptors:[tableView sortDescriptors]];

  [self setDataArray:mutableDataArray];
  [[self nameOnlyTableView] reloadData];
}

【问题讨论】:

    标签: objective-c cocoa interface-builder nstablecolumn


    【解决方案1】:

    事实证明,不仅表格列需要可编辑,单元格视图中的文本字段也需要。选择此文本字段并从“行为”菜单中选择“可编辑”解决了该问题。

    【讨论】:

      猜你喜欢
      • 2014-02-05
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 2013-05-29
      相关资源
      最近更新 更多