Problem naming NSTableColumn

回眸只為那壹抹淺笑 提交于 2019-12-22 09:03:36

问题


I'm trying to create a column with an empty string as the identifier but Cocoa seems to replace the empty string with the word "Field" every time I try to create the column. How do you go around this?

- (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];
}

回答1:


A column's identifier is not the same thing as its title. You want to set its -headerCell's string value:

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


来源:https://stackoverflow.com/questions/2134478/problem-naming-nstablecolumn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!