问题命名NSTableColumn

rui*_*eco 4 cocoa objective-c nstableview nstablecolumn

我正在尝试使用空字符串作为标识符创建一个列,但每当我尝试创建列时,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];
}
Run Code Online (Sandbox Code Playgroud)

Jos*_*zzi 10

列的标识符与其标题不同.您想要设置其-headerCell的字符串值:

[[columnColumn headerCell] setStringValue:@""];
Run Code Online (Sandbox Code Playgroud)

  • 我认为它在代码中相当不直观.NSControl和子类将消息传递到它们的单元格.我认为NSTableColumn应该有一个-title/-setTitle:方法,它将字符串传递给标题单元格的字符串值.有人应该提交增强请求......但我太懒了.:-) (2认同)