简体   繁体   English

NSTableCell setDataCell禁用编辑

[英]NSTableCell setDataCell disables editing

I have a NSTableView which I dynamically add columns. 我有一个NSTableView我动态添加列。 I've just added a call to setDataCell to customize my cell. 我刚刚添加了对setDataCell的调用以自定义我的单元格。 The code looks like: 代码如下:

for(NSUInteger columnIndex = 0; columnIndex < resultSet.columNames.count; ++columnIndex)
{
    NSTableColumn * newColumn = [[NSTableColumn alloc] initWithIdentifier: [NSString stringWithFormat: @"%ld", columnIndex]];

    [newColumn.headerCell setAlignment: NSCenterTextAlignment];
    [newColumn.headerCell setStringValue: resultSet.columNames[columnIndex]];
    [newColumn setDataCell: [[HSDisclosureTextFieldCell alloc] init]];
    [newColumn setEditable: YES];

    [resultsTableView addTableColumn: newColumn];
    if(newColumn.width < 60) [newColumn sizeToFit];
} // End of column loop

If I remove the call to setDataCell then I can still double click my entry and edit it. 如果删除对setDataCell的调用,则仍然可以双击我的条目并进行编辑。

I have minimized the HSDisclosureTextFieldCell contains the following (no overrides): 我已最小化HSDisclosureTextFieldCell包含以下内容(无替代):

@interface HSDisclosureTextFieldCell : NSTextFieldCell
{
}

But I still cannot double click to edit the field anymore. 但是我仍然无法双击来编辑该字段。

Any ideas where I'm going wrong? 有什么想法我要去哪里吗?

Turns out even though I am doing: 原来,即使我在做:

[newColumn setEditable: YES];

and have: 并具有:

- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

implemented, I needed to switch my setDataCell to be: 实现后,我需要将setDataCell切换为:

HSDisclosureTextFieldCell * cell = [[HSDisclosureTextFieldCell alloc] init];
[cell setEditable: YES];
[newColumn setDataCell: cell];

Now that I have done that, everything seems to be working properly. 既然我已经做到了,那么一切似乎都可以正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM