【问题标题】:Problem naming NSTableColumn命名 NSTableColumn 的问题
【发布时间】:2011-01-09 05:17:26
【问题描述】:

我正在尝试创建一个以空字符串作为标识符的列,但每次我尝试创建该列时,Cocoa 似乎都会用单词“Field”替换空字符串。你如何解决这个问题?

- (void)addColumnWithCheckboxToTable:(NSTableView *)table
{
    // Add column with checkbox before all other columns
    // This column will have no title and should be as wide as the checkbox
    NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@" "] autorelease];

    // The checkbox is to be initialised without a title
    NSButtonCell *checkbox = [[[NSButtonCell alloc] initTextCell:@" "] autorelease];
    [checkbox setEditable:YES];
    [checkbox setButtonType:NSSwitchButton];
    [checkbox setImagePosition:NSImageOnly];
    [checkbox setControlSize:NSSmallControlSize];

    // Add column with checkbox to table
    [column setDataCell:checkbox];

    // Add column to table
    [table addTableColumn:column];
}

【问题讨论】:

    标签: objective-c cocoa nstableview nstablecolumn


    【解决方案1】:

    列的标识符与其标题不同。你想设置它的 -headerCell 的字符串值:

    [[columnColumn headerCell] setStringValue:@""];
    

    【讨论】:

    • 我认为这在代码中相当不直观。 NSControl 和子类将消息传递到它们的单元格。我认为 NSTableColumn 应该有一个 -title/-setTitle: 将字符串传递给标题单元格的字符串值的方法。有人应该提出增强请求……但我懒得做。 :-)
    猜你喜欢
    • 2018-07-26
    • 1970-01-01
    • 2017-12-18
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 2011-02-05
    相关资源
    最近更新 更多