2014-09-10 33 views
0

我正在創建NSTableView,並且在更改TableColumns時出現問題。數據的重新加載時,標題顯示爲黑色。在重新加載時在NSTableView上創建動態列

for (int i = 0; i < sqlite3_column_count(stmp); i++) { 
    NSTableColumn *tableColumn = [NSTableColumn new]; 
    NSString *columnName = [NSString stringWithUTF8String:sqlite3_column_name(stmp, i)]; 

    [tableColumn setIdentifier:columnName]; 
    NSCell *cell = [[NSCell alloc] initTextCell:columnName]; 
    [cell setFont:[NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]]; 
    [tableColumn setHeaderCell:cell]; 
    [tableView addTableColumn:tableColumn]; 
} 

我該如何重新加載此標頭而不丟失樣式?

NSTableView

EDIT 1

for (int i = 0; i < sqlite3_column_count(stmp); i++) { 
    NSTableColumn *tableColumn = [NSTableColumn new]; 
    NSString *columnName = [NSString stringWithUTF8String:sqlite3_column_name(stmp, i)]; 

    [tableColumn setIdentifier:columnName]; 

    NSTextFieldCell *cell = [[NSTextFieldCell alloc] initTextCell:columnName]; 

    [cell setTextColor:[NSColor whiteColor]]; 
    [tableColumn setHeaderCell:cell]; 

    [self.tableView addTableColumn:tableColumn]; 
} 

此代碼出現在標題列但在NSTableView頭的不相同的初始風格的名稱。

enter image description here

+0

不知道你在問什麼,你是說你的標題行是在初始化時確定的,但是在你重新加載數據後它會變成黑色? – 2014-09-11 12:45:32

+0

我將'NSCell'更改爲'NSTextFieldCell',並且在標題中不帶樣式地工作。這使改變顏色的文字。但在這個過程中失去了風格。 – Jones 2014-09-11 14:59:34

+0

你可能會發布更多的圖片和代碼?我不確定我是否看到這裏的全貌 – 2014-09-11 15:45:14

回答

0

我的頭樣式複製到臨時變量中,初始化xib

... 
[self copyColumnConfiguration:columnTemplate fromColumn:self.tableView.tableColumns[0]]; 
... 

- (void)copyColumnConfiguration:(NSTableColumn*)dstColumn fromColumn: (NSTableColumn*)srcColumn 
{ 
    id srcCell; 
    id dstCell; 

    srcCell = [srcColumn dataCell]; 
    dstCell = [dstColumn dataCell]; 
    [dstCell setAlignment:[srcCell alignment]]; 
    [dstCell setFormatter:[srcCell formatter]]; 

    srcCell = [srcColumn headerCell]; 
    dstCell = [dstColumn headerCell]; 
    [dstCell setAlignment:[srcCell alignment]]; 
} 

,創造列複製到新列之後存儲的風格。 欲瞭解更多信息,請參閱http://lists.apple.com/archives/cocoa-dev/2005/Nov/msg00949.html

相關問題